The ARG and ENV statements use for define variables in to Dockerfile. It may be difficult to understand the difference. The difference is when variables will be utilized.
If you need build-time customization, ARG is best choice. From docker reference:
ARGinstruction defines a variable that users can pass at build-time to the builder with the docker build command using the –build-arg
If you need run-time customization (to run the same image with different settings), ENV is well-suited. What you should know from docs:
ENVinstruction sets the environment variable
to the value . The environment variables set using ENV will persist when a container is run from the resulting image.
To define them as the command line instructions use next (for
ARG var or ):
docker build --build-arg var=xxx
docker run --env var=yyy
The best way define them is write a docker-compose file with defined next section:
version: "3" services: ubuntu: build: context: . args: var: xxx environment: var: yyy
To run container with build image use next command
docker-compose up --build
I hope this explanation has helped you to learn a bit more about using dockerfile statements, and will save you time to understand the basis of Docker.