I am working on a task that involves building a docker image with centOs as its base using a Dockerfile . One of the steps inside the dockerfile needs http_proxy and https_proxy ENV variables to be set in order to work behind the proxy.
As this Dockerfile will be used by multiple teams having different proxies, I want to avoid having to edit the Dockerfile for each team. Instead I am looking for a solution which allows me to pass ENV variables at build time, e.g.,
sudo docker build -e http_proxy=somevalue .
I'm not sure if there is already an option that provides this. Am I missing something?
Containers can be built using
build arguments
(in Docker 1.9+) which work like environment variables.Here is the method:
and then build a production container:
docker build --build-arg APP_ENV=prod .
For your particular problem:
and then run:
docker build --build-arg http_proxy=10.11.24.31 .
Note that if you build your containers with
docker-compose
, you can specify these build-args in thedocker-compose.yml
file, but not on the command-line. However, you can use variable substitution in thedocker-compose.yml
file, which uses environment variables.I faced the same situation.
According to Sin30's answer pretty solution is using shell,