Dockerfile 无法连接代理服务器

时间:2021-06-27 04:49:14

标签: docker

当我在 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

从 jenkins vm 构建 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)

1 个答案:

答案 0 :(得分:0)

我在构建 docker 镜像时使用 --network 主机选项解决了上述问题。

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