gpt4 book ai didi

build - Docker build 没有网络,但是 docker run 有

转载 作者:IT老高 更新时间:2023-10-28 21:38:04 24 4
gpt4 key购买 nike

如果我想构建我的 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

但如果我通过 docker run 运行完全相同的命令,它就可以工作:

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。

提前致谢

最佳答案

使用以下命令检查主机上可用的网络:

docker network ls

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

现在假设您在您的Dokerfile 可用的目录中。 ,建立你的图像附加标志--networks并更改 <image-name>和你的:

docker build . -t <image-name> --no-cache --network=host

关于build - Docker build 没有网络,但是 docker run 有,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31763418/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com