Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass arguments to a Dockerfile?

People also ask

How do I pass a variable in docker run?

With a Command Line Argument The command used to launch Docker containers, docker run , accepts ENV variables as arguments. Simply run it with the -e flag, shorthand for --env , and pass in the key=value pair: sudo docker run -e POSTGRES_USER='postgres' -e POSTGRES_PASSWORD='password' ...

Can I use environment variables in Dockerfile?

Dockerfile provides a dedicated variable type ENV to create an environment variable. We can access ENV values during the build, as well as once the container runs.


You are looking for --build-arg and the ARG instruction. These are new as of Docker 1.9.

Check out this document for reference. This will allow you to add ARG arg to the Dockerfile and then build with

docker build --build-arg arg=2.3 .