dockerd set default environment variable for all containers

Multi tool use
Multi tool use


dockerd set default environment variable for all containers



I have a docker daemon running behind an HTTP proxy.



My Dockerfile's look like this:


Dockerfile


FROM alpine:latest

RUN apk add --no-cache make gcc



Normally I configure the proxy by adding the http_proxy environment variable to the Dockerfile:


http_proxy


Dockerfile


FROM alpine:latest

ENV http_proxy http://myproxy.mydomain.com:8080/

RUN apk add --no-cache make gcc



And that works fine.



But I don't want to touch the Dockerfile because it is also used in other environments where the proxy isn't available. I don't want to have ENV http_proxy ... in the Dockerfile at all.


Dockerfile


ENV http_proxy ...


Dockerfile



So my question is: how to add an environment variable to all containers without touching the Dockerfiles?


Dockerfile





@rustyxI posted my answer try this below
– Chandru
Jun 1 at 14:03





Maybe related: stackoverflow.com/questions/34322631/…
– Hemerson Varela
Jun 1 at 14:03




2 Answers
2



Try like this



Dockerfile


FROM alpine:latest

ARG HTTP_PROXY_ARGUMENT

ENV http_proxy ${HTTP_PROXY_ARGUMENT}

RUN apk add --no-cache make gcc



Build like below


docker build -t --build-arg HTTP_PROXY_ARGUMENT=http://myproxy.mydomain.com:8080/ imagename .



With adding a environment variable on run ?



https://docs.docker.com/engine/reference/run/#env-environment-variables






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

xNlLplhDVJzykc37Slsk udOyfEafZlXgphZrzofa,kkACBzI,JP7b
PMII2D,BiHi5,PDhQ,qi68Xa,4w4uInJ3c1Wo,2KDm

Popular posts from this blog

PHP contact form sending but not receiving emails

Do graphics cards have individual ID by which single devices can be distinguished?

Create weekly swift ios local notifications