config alpine's proxy in dockerfile
It seems like you're required to set http_proxy
in your Dockerfile. If you do (e.g. for a specific, temporary reason - say you're building your container behind a corporate proxy) and subsequently don't need it anymore I'd suggest something like the following:
RUN export \
http_proxy="http://some.custom.proxy:8080/” \
https_proxy="https://some.custom.proxy:8080/" \
\
&& < E.G. pip install requirements.txt> \
\
&& unset http_proxy https_proxy
You can also use a more permanent solution in your Dockerfile by invoking ENV
, but be aware that these are persisted and can lead to problems further down the road if you push/deploy your images somewhere else - Reference.
yuxh
Updated on June 04, 2022Comments
-
yuxh almost 2 years
I use mvn clean package docker:build to invoke dockerfile(docker version 18.03.1-ce ) in machine B:
FROM openjdk:8-jdk-alpine RUN apk update && apk upgrade && apk add netcat-openbsd && apk add curl
it turns out:
Step 2/8 : RUN apk update && apk upgrade && apk add netcat-openbsd && apk add curl ---> Running in 89c9b97b9d75 fetch http://dl-cdn.alpinelinux.org/alpine/v3.7/main/x86_64/APKINDEX.tar.gz fetch http://dl-cdn.alpinelinux.org/alpine/v3.7/community/x86_64/APKINDEX.tar.gz ERROR: http://dl-cdn.alpinelinux.org/alpine/v3.7/main: temporary error (try again later) WARNING: Ignoring APKINDEX.70c88391.tar.gz: No such file or directory
I figure out it's network problem,machine B access internet by machine A,I have tried add "dns" in /etc/docker/daemon.json, "httpProxy" in ~/.docker/config.json , now I success in running:
`docker run -it cc2179b8f042` apk update
but when I come back to use maven invoking dockfile ,it doesn't work. So how can I make dockfile work and tell me any difference between this two case.
-
fly2matrix almost 6 yearstry passing a build-argument
http_proxy
with correct value. -
yuxh almost 6 yearsI use mvn clean package docker:build -Ddocker.buildArg.http_proxy=xx ,still not work. I fix it by adding "ENV http_proxy xx" in dockfile for now .
-
fly2matrix almost 6 yearsYou can try setting this in pom.xml , Take a look at github.com/spotify/dockerfile-maven/pull/41
-
yuxh almost 6 yearsI use old docker-maven-plugin 1.1.1 and put a issue in github . I will check dockerfile-maven later.
-
-
Mayur over 5 yearsIs there any config file so that we can specify proxy in it?
-
heldic over 5 yearsNot sure if that's what you're aiming at, but you can configure a proxy for Docker, yes. The config file would be in
~/.docker/config.json
- check this doc. You can also edit this in your Docker preferences if you use e.g. Docker for Mac -
Mayur over 5 yearsHey @heldic Thanks for your comment. I was aiming for how to use/set proxy to build dockerfile. Using that proxy I supposed to download packages. I have set proxy as environment variable in docker file, but while building docker file it shows proxy error 'Permission denied' so is it any other way or its an issue with proxy server?