Dockerfile无法连接代理服务器



当我在Linux VM docker文件中运行docker文件时,我有一个docker文件可以从远程存储库中获取包,创建docker映像时不会出现任何问题。

当我从Jenkins管道调用时,相同的Docker文件无法访问网络。

cat Dockerfile
FROM docker-registry-remote.artifactory.myrepo.com/node
ADD myapp /usr/src/app/myapp
ENV http_proxy=http://10.1.2.3:8080/
ENV https_proxy=http://10.1.2.3:8080/
RUN apt-get update

Jenkins构建日志Err:9 http://deb.debian.org/debian stretch/main amd64 Packages Cannot initiate the connection to 10.1.2.3:8080 (10.1.2.3). - connect (101: Network is unreachable)

来自jenkins-vm-的ping测试

[root@ip-10-1-1-1 tmp]# ping 10.1.2.3
PING 10.1.2.3 (10.1.2.3) 56(84) bytes of data.
64 bytes from 10.1.2.3: icmp_seq=1 ttl=247 time=22.9 ms
64 bytes from 10.1.2.3: icmp_seq=2 ttl=247 time=22.5 ms
64 bytes from 10.1.2.3: icmp_seq=3 ttl=247 time=22.3 ms
64 bytes from 10.1.2.3: icmp_seq=4 ttl=247 time=22.3 ms
64 bytes from 10.1.2.3: icmp_seq=5 ttl=247 time=22.3 ms
64 bytes from 10.1.2.3: icmp_seq=6 ttl=247 time=22.4 ms
^C
--- 10.1.2.3 ping statistics ---
6 packets transmitted, 6 received, 0% packet loss, time 5002ms
rtt min/avg/max/mdev = 22.357/22.531/22.968/0.211 ms

从jenkinsvm 构建docker镜像

Ign:11 http://deb.debian.org/debian stretch-updates/main amd64 Packages
Ign:12 http://deb.debian.org/debian stretch-updates/main all Packages
Err:9 http://deb.debian.org/debian stretch/main amd64 Packages
Cannot initiate the connection to 10.1.2.3:8080 (10.1.2.3). - connect (101: Network is unreachable)
Ign:10 http://deb.debian.org/debian stretch/main all Packages
Err:11 http://deb.debian.org/debian stretch-updates/main amd64 Packages
Cannot initiate the connection to 10.1.2.3:8080 (10.1.2.3). - connect (101: Network is unreachable)
Ign:12 http://deb.debian.org/debian stretch-updates/main all Packages
Reading package lists...
W: The repository 'http://security.debian.org/debian-security stretch/updates Release' does not have a Release file.
W: The repository 'http://deb.debian.org/debian stretch Release' does not have a Release file.
W: The repository 'http://deb.debian.org/debian stretch-updates Release' does not have a Release file.
E: Failed to fetch http://security.debian.org/debian-security/dists/stretch/updates/main/binary-amd64/Packages  Cannot initiate the connection to 10.1.2.3:8080 (10.1.2.3). - connect (101: Network is unreachable)
E: Failed to fetch http://deb.debian.org/debian/dists/stretch/main/binary-amd64/Packages  Cannot initiate the connection to 10.1.2.3:8080 (10.1.2.3). - connect (101: Network is unreachable)

在构建docker映像时,我使用--network host选项解决了上述问题。

docker build -f Dockerfile --network host --no-cache -t mytag .

最新更新