Reputation: 1087
I have 2 Dockerfiles that have common arguments (ARG) that are passed to the actual commands (RUN) to build the images.
Is it possible to provide an external file with the arguments so that when I need to update one of them I don't need to touch both Dockerfiles?
Upvotes: 2
Views: 2446
Reputation: 265055
An ARG
is designed to be modified from the build command line, so you'd run:
docker build --build-arg VAR=value -t your_image .
That can be placed inside of a shell script to automate it and pass the same arg to each build.
You can also use a compose file, and the compose file may use environment variables or a .env
file, to set variables used inside the compose file, e.g.
build:
context: ./your_app_dir
dockerfile: Dockerfile
args:
VAR: ${VALUE}
And the .env
would contain:
VALUE=your_value
For more details on compose files, see the build syntax and also the environment file syntax.
Upvotes: 5