Passing build arguments to Dockerfile and converting them as environment variables
Imagine you are building a dockerfile and you need to control the build process using an ENV variable which you pass from outside during the build process.
In our case, the variable is MODE. MODE can have 2 values DEV and PROD. By Default we need the value to be DEV
The dockerfile for thesame is given belwo
Dockerfile
ARG MODE=DEV
ENV MODE=$MODE
Now to pass the value during build process use the
docker build --build-arg MODE=PROD -t test-docker-image .