You should use the
ARG directive in your Dockerfile which is meant for this purpose.
ARGinstruction defines a variable that users can pass at build-time to the builder with the docker build command using the
So your Dockerfile will have this line:
or if you’d prefer a default value:
Now you can reference this variable inside your Dockerfile:
then you will build your container like so:
$ docker build --build-arg request_domain=mydomain Dockerfile
Note 1: Your image will not build if you have referenced an
ARG in your Dockerfile but excluded it in
Note 2: If a user specifies a build argument that was not defined in the Dockerfile, the build outputs a warning:
[Warning] One or more build-args [foo] were not consumed.