0

I have a docker daemon running behind an HTTP proxy.

My Dockerfile's look like this:

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:

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.

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

2

2 Answers 2

1

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 .
Sign up to request clarification or add additional context in comments.

Comments

0

With adding a environment variable on run ?

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.