Docker构建没有网络,但是docker run有

swe*_*ler 6 dns build apt-get docker

如果我想构建我的Dockerfile,它无法连接到网络或至少DNS:

Sending build context to Docker daemon 15.95 MB
Sending build context to Docker daemon 
Step 0 : FROM ruby
 ---> eeb85dfaa855
Step 1 : RUN apt-get update -qq && apt-get install -y build-essential libpq-dev
 ---> Running in ec8cbd41bcff
W: Failed to fetch http://httpredir.debian.org/debian/dists/jessie/InRelease  

W: Failed to fetch http://httpredir.debian.org/debian/dists/jessie-updates/InRelease  

W: Failed to fetch http://security.debian.org/dists/jessie/updates/InRelease  

W: Failed to fetch http://httpredir.debian.org/debian/dists/jessie/Release.gpg  Could not resolve 'httpredir.debian.org'

W: Failed to fetch http://httpredir.debian.org/debian/dists/jessie-updates/Release.gpg  Could not resolve 'httpredir.debian.org'

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 build-essential
INFO[0001] The command "/bin/sh -c apt-get update -qq && apt-get install -y build-essential libpq-dev" returned a non-zero code: 100
Run Code Online (Sandbox Code Playgroud)

但如果我通过docker run它运行完全相同的命令:

docker run --name="test" ruby /bin/sh -c 'apt-get update -qq && apt-get install -y build-essential libpq-dev'
Run Code Online (Sandbox Code Playgroud)

有人有想法,为什么docker build不起作用?我已经在StackOverflow上尝试了所有与DNS相关的tipp,比如使用--dns 8.8.8.8等启动docker.

提前致谢

Raf*_*ffa 35

使用以下命令检查主机上有哪些网络可用:

docker network ls
Run Code Online (Sandbox Code Playgroud)

然后选择一个你知道有效的人选,这个host人可能是一个很好的候选人。

现在假设您位于可用的目录中Dokerfile,构建附加标志的图像--networks并用您的更改<image-name>

docker build . -t <image-name> --no-cache --network=host
Run Code Online (Sandbox Code Playgroud)


Joh*_*nts 17

Docker 似乎确实存在一些网络问题。我设法解决了这个问题

systemctl restart docker

...这基本上只是 Debian 8 中的 unix 级别的“restart-the-daemon”命令。


小智 7

我有类似的问题。但当我运行 AWS linux 时,我没有 systemctl。我解决了使用:

sudo service docker restart
Run Code Online (Sandbox Code Playgroud)


Hat*_*ber -2

一些建议,不确定是否有效。你能...apt-get install -y...改成...apt-get install -yqq...

另外,您尝试构建的图像是否发生了变化?