Linux环境下,有时需要通过http proxy连接Internet的。通过export http_proxy=http://proxyhost:proxyport来上网。

那么 执行Docker build时,执行过程中提示连接不到网络。

找到三种办法, 如下:

1. 在Docker file 里面写上,ENV http_proxy http://proxyhost:proxyport

    但这样的话,就把http_proxy写死到dockerfile中了。使用这个image的人就麻烦了,他要通过这样的方式来run。    

      docker run --env http_proxy=http://10.128.46.150:3128/ my/http-client

Dockerfile:
FROM debian:wheezy
env http_proxy "http://xxx:8080"
env https_proxy "http://xxx:8080"
env ftp_proxy "http://xxx:8080"
RUN apt-get update && apt-get install -y cowsay fortune

2. 对第一种方法改进。在Docker file 里面先写上,ENV http_proxy http://proxyhost:proxyport。最后在把

    ENV http_proxy " "

3. Docker build时,指定--build-arg flag

$ docker build --build-arg HTTP_PROXY=http://10.20.30.2:1234 .

docker build . -f Dockerfile.frontendapi \
	-t registry.cn-shanghai.aliyuncs.com/ouou/openmatch-frontendapi:dev \
	--network host \
	--build-arg HTTP_PROXY=http://127.0.0.1:1080 \
	--build-arg HTTPS_PROXY=http://127.0.0.1:1080

参考:

[root@ouou java]# docker build \
--build-arg https_proxy=$HTTP_PROXY --build-arg http_proxy=$HTTP_PROXY \ 
--build-arg HTTP_PROXY=$HTTP_PROXY --build-arg HTTPS_PROXY=$HTTP_PROXY \
--build-arg NO_PROXY=$NO_PROXY --build-arg no_proxy=$NO_PROXY -t java .

 

Logo

有“AI”的1024 = 2048,欢迎大家加入2048 AI社区

更多推荐