构建 Docker 图像时无法找到包
Unable to locate package while building Docker image
在我的 Docker 容器构建过程中,我尝试使用 apt-get install 安装一些包。但是,该过程未能完成,因为找不到 4 个包中的 3 个。
Step 1 : RUN apt-get update && apt-get install -y netcat ca-certificates build-essential libssl-dev
---> Running in 38d22d97ec4a
Err http://http.debian.net jessie InRelease
Err http://http.debian.net jessie-updates InRelease
Err http://security.debian.org jessie/updates InRelease
Err http://http.debian.net jessie Release.gpg
Could not resolve 'http.debian.net'
Err http://security.debian.org jessie/updates Release.gpg
Could not resolve 'security.debian.org'
Err http://http.debian.net jessie-updates Release.gpg
Could not resolve 'http.debian.net'
Reading package lists...
W: Failed to fetch http://http.debian.net/debian/dists/jessie/InRelease
W: Failed to fetch http://http.debian.net/debian/dists/jessie-updates/InRelease
W: Failed to fetch http://security.debian.org/dists/jessie/updates/InRelease
W: Failed to fetch http://http.debian.net/debian/dists/jessie/Release.gpg Could not resolve 'http.debian.net'
W: Failed to fetch http://http.debian.net/debian/dists/jessie-updates/Release.gpg Could not resolve 'http.debian.net'
W: Failed to fetch http://security.debian.org/dists/jessie/updates/Release.gpg Could not resolve 'security.debian.org'
W: Some index files failed to download. They have been ignored, or old ones used instead.
Reading package lists...
Building dependency tree...
Reading state information...
E: Unable to locate package netcat
E: Unable to locate package build-essential
E: Unable to locate package libssl-dev
Removing intermediate container 38d22d97ec4a
2015/08/10 12:03:07 The command [/bin/sh -c apt-get update && apt-get install -y netcat ca-certificates build-essential libssl-dev] returned a non-zero code: 100
起初,我认为这是我的基本映像的问题,但是我在另一个 VM 上构建容器没有问题。想法?
此问题与主机的网络配置有关。 eth0 接口配置不正确。以下命令帮助我确定这是一个 DNS 问题。
$ docker run --rm debian:jessie ping -c 5 google.com
ping: unknown host
$ docker run --rm debian:jessie ping -c 5 8.8.8.8
PING 8.8.8.8 (8.8.8.8): 56 data bytes
64 bytes from 8.8.8.8: icmp_seq=0 ttl=38 time=37.147 ms
64 bytes from 8.8.8.8: icmp_seq=1 ttl=38 time=32.917 ms
64 bytes from 8.8.8.8: icmp_seq=2 ttl=38 time=31.475 ms
64 bytes from 8.8.8.8: icmp_seq=3 ttl=38 time=30.692 ms
64 bytes from 8.8.8.8: icmp_seq=4 ttl=38 time=31.180 ms
--- 8.8.8.8 ping statistics ---
5 packets transmitted, 5 packets received, 0% packet loss
round-trip min/avg/max/stddev = 30.692/32.682/37.147/2.352 ms
我在一个基于相同问题的较新问题中找到了这个答案,它为我解决了这个问题。
$ docker-machine restart default # Restart the environment
$ eval $(docker-machine env default) # Refresh your environment settings
答案由Mark Smith提供。
在我的 Docker 容器构建过程中,我尝试使用 apt-get install 安装一些包。但是,该过程未能完成,因为找不到 4 个包中的 3 个。
Step 1 : RUN apt-get update && apt-get install -y netcat ca-certificates build-essential libssl-dev
---> Running in 38d22d97ec4a
Err http://http.debian.net jessie InRelease
Err http://http.debian.net jessie-updates InRelease
Err http://security.debian.org jessie/updates InRelease
Err http://http.debian.net jessie Release.gpg
Could not resolve 'http.debian.net'
Err http://security.debian.org jessie/updates Release.gpg
Could not resolve 'security.debian.org'
Err http://http.debian.net jessie-updates Release.gpg
Could not resolve 'http.debian.net'
Reading package lists...
W: Failed to fetch http://http.debian.net/debian/dists/jessie/InRelease
W: Failed to fetch http://http.debian.net/debian/dists/jessie-updates/InRelease
W: Failed to fetch http://security.debian.org/dists/jessie/updates/InRelease
W: Failed to fetch http://http.debian.net/debian/dists/jessie/Release.gpg Could not resolve 'http.debian.net'
W: Failed to fetch http://http.debian.net/debian/dists/jessie-updates/Release.gpg Could not resolve 'http.debian.net'
W: Failed to fetch http://security.debian.org/dists/jessie/updates/Release.gpg Could not resolve 'security.debian.org'
W: Some index files failed to download. They have been ignored, or old ones used instead.
Reading package lists...
Building dependency tree...
Reading state information...
E: Unable to locate package netcat
E: Unable to locate package build-essential
E: Unable to locate package libssl-dev
Removing intermediate container 38d22d97ec4a
2015/08/10 12:03:07 The command [/bin/sh -c apt-get update && apt-get install -y netcat ca-certificates build-essential libssl-dev] returned a non-zero code: 100
起初,我认为这是我的基本映像的问题,但是我在另一个 VM 上构建容器没有问题。想法?
此问题与主机的网络配置有关。 eth0 接口配置不正确。以下命令帮助我确定这是一个 DNS 问题。
$ docker run --rm debian:jessie ping -c 5 google.com
ping: unknown host
$ docker run --rm debian:jessie ping -c 5 8.8.8.8
PING 8.8.8.8 (8.8.8.8): 56 data bytes
64 bytes from 8.8.8.8: icmp_seq=0 ttl=38 time=37.147 ms
64 bytes from 8.8.8.8: icmp_seq=1 ttl=38 time=32.917 ms
64 bytes from 8.8.8.8: icmp_seq=2 ttl=38 time=31.475 ms
64 bytes from 8.8.8.8: icmp_seq=3 ttl=38 time=30.692 ms
64 bytes from 8.8.8.8: icmp_seq=4 ttl=38 time=31.180 ms
--- 8.8.8.8 ping statistics ---
5 packets transmitted, 5 packets received, 0% packet loss
round-trip min/avg/max/stddev = 30.692/32.682/37.147/2.352 ms
我在一个基于相同问题的较新问题中找到了这个答案,它为我解决了这个问题。
$ docker-machine restart default # Restart the environment
$ eval $(docker-machine env default) # Refresh your environment settings
答案由Mark Smith提供。