yuxh
yuxh

Reputation: 954

config alpine's proxy in dockerfile

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.

Upvotes: 8

Views: 35619

Answers (2)

klonez klonez
klonez klonez

Reputation: 51

You can set proxy using high case environment variables.

ENV HTTP_PROXY "http://<your proxy ip>:<your proxy port>"
ENV HTTPS_PROXY "http://<your proxy ip>:<your proxy port>"
RUN apk add --no-cache python2

I hope, this will helps.

Upvotes: 1

heldic
heldic

Reputation: 405


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.

Upvotes: 9

Related Questions