Docker 文件中的 RUN yum 不起作用,但 yum 在容器内起作用

Docker 文件中的 RUN yum 不起作用,但 yum 在容器内起作用

我正在尝试从 amazonlinux(基于 fedora)构建一个容器。

如果我构建镜像并进入容器,yum 命令可以正常工作。但是,如果我将 yum 命令放在 Dockerfile 中,它就不起作用了。似乎无法联系存储库

Dockerfile

FROM amazonlinux
RUN yum update -y

正在运行:sudo docker build。

Sending build context to Docker daemon  3.072kB
Step 1/2 : FROM amazonlinux
---> df7d0b6ddeee
Step 2/2 : RUN yum update -y
---> Running in 14e4e4bad5b1
Loaded plugins: ovl, priorities

结果,尝试了几次 https,最终:

...URLError: (28, 'Resolving timed out after 5516 milliseconds')
Trying other mirror...
The command '/bin/sh -c yum update -y' returned a non-zero code: 1

答案1

如果我是你我会检查以下事项:

  • 尝试 Centos7 镜像并运行相同的命令
  • yum clean all在运行更新之前尝试运行,因此它应该看起来像这样RUN yum clean all && yum update -y
  • 检查 DNS 解析中的网络限制,您可以检查这一点关联以供参考,还有这个指导从docker配置自定义网络
  • 还要检查主机上的防火墙配置

答案2

如果容器遇到 DNS 问题,请尝试使用主机网络,例如

docker build .... --network host ....

相关内容