Docker构建没有网络,但是docker运行有 [英] Docker build has no network, but docker run has
本文介绍了Docker构建没有网络,但是docker运行有的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我要构建我的Docker文件,它不能连接到网络或至少DNS:
If I want to build my Dockerfile, it can't connect to the network or at least 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
但是,如果我通过 docker run
运行完全相同的命令,它的工作原理是:
But if I run exactly the same command via docker run
it works:
docker run --name="test" ruby /bin/sh -c 'apt-get update -qq && apt-get install -y build-essential libpq-dev'
有人有想法,为什么 docker build
不工作?我已经尝试了StackOverflow上的所有DNS相关提示,例如使用--dns 8.8.8.8等启动docker。
Does anybody have an idea, why docker build
does not work? I have tried all DNS related tipps on StackOverflow, like starting docker with --dns 8.8.8.8 etc.
提前感谢
推荐答案
我也有类似的问题。但是当我运行AWS linux时,我没有systemctl。我解决了:
I had similar problem. But as I was running AWS linux i had no systemctl. I solved using:
sudo service docker restart
这篇关于Docker构建没有网络,但是docker运行有的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文