【发布时间】:2020-12-12 17:32:37
【问题描述】:
我正在尝试学习 Docker,并且我在 CentOS8 上使用 Oracle VMware。我正在尝试构建一个 Dockerfile。以下是文件 Dockerfile 的内容:
FROM centos
RUN yum -y install httpd
当我构建时,它会抛出以下错误:
[arijhit@localhost docker-images]$ docker build --tag centos_apache:v1 .
Sending build context to Docker daemon 2.048kB
Step 1/2 : FROM centos
---> 0d120b6ccaa8
Step 2/2 : RUN yum -y install httpd
---> Running in 1f20ba141039
CentOS-8 - AppStream 0.0 B/s | 0 B 00:30
Errors during downloading metadata for repository 'AppStream':
- Curl error (6): Couldn't resolve host name for http://mirrorlist.centos.org/?release=8&arch=x86_64&repo=AppStream&infra=container [Could not resolve host: mirrorlist.centos.org]
Error: Failed to download metadata for repo 'AppStream': Cannot prepare internal mirrorlist: Curl error (6): Couldn't resolve host name for http://mirrorlist.centos.org/?release=8&arch=x86_64&repo=AppStream&infra=container [Could not resolve host: mirrorlist.centos.org]**
The command '/bin/sh -c yum -y install httpd' returned a non-zero code: 1
有人可以帮忙解决这个问题吗?
编辑:
嗨 @Uberhumus 这是 CentOS docker 镜像对你所说的命令的响应
[arijhit@localhost ~]$ docker run -t -d centos 60566bb1a2ef808c59c0374c0e9753bc26f0098c8b54c438e7742af418beae3a
[arijhit@localhost ~]$ docker p
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
60566bb1a2ef centos "/bin/bash" 20 seconds ago Up 8 seconds laughing_greider
5d3efb03c67a nginx:alpine "/docker-entrypoint.…" 6 minutes ago Up 5 minutes 80/tcp kind_tesla
[arijhit@localhost ~]$ docker exec -it laughing_greider /bin/bash
[root@60566bb1a2ef /]# ping 8.8.8.8
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
64 bytes from 8.8.8.8: icmp_seq=1 ttl=115 time=31.4 ms
64 bytes from 8.8.8.8: icmp_seq=2 ttl=115 time=168 ms
64 bytes from 8.8.8.8: icmp_seq=3 ttl=115 time=47.3 ms
^C
--- 8.8.8.8 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 5ms
rtt min/avg/max/mdev = 31.357/82.241/168.110/61.064 ms
[root@60566bb1a2ef /]# yum check-update
Failed to set locale, defaulting to C.UTF-8
CentOS-8 - AppStream 0.0 B/s | 0 B 00:30
Errors during downloading metadata for repository 'AppStream':
- Curl error (6): Couldn't resolve host name for http://mirrorlist.centos.org/?release=8&arch=x86_64&repo=AppStream&infra=container [Could not resolve host: mirrorlist.centos.org] Error: Failed to download metadata for repo 'AppStream': Cannot prepare internal mirrorlist: Curl error (6): Couldn't resolve host name for http://mirrorlist.centos.org/?release=8&arch=x86_64&repo=AppStream&infra=container [Could not resolve host: mirrorlist.centos.org]
[root@60566bb1a2ef /]# yum -y install httpd
Failed to set locale, defaulting to C.UTF-8
CentOS-8 - AppStream 0.0 B/s | 0 B 00:30
Errors during downloading metadata for repository 'AppStream':
- Curl error (6): Couldn't resolve host name for http://mirrorlist.centos.org/?release=8&arch=x86_64&repo=AppStream&infra=container [Could not resolve host: mirrorlist.centos.org] Error: Failed to download metadata for repo 'AppStream': Cannot prepare internal mirrorlist: Curl error (6): Couldn't resolve host name for http://mirrorlist.centos.org/?release=8&arch=x86_64&repo=AppStream&infra=container [Could not resolve host: mirrorlist.centos.org]
【问题讨论】:
-
你尝试过做什么?具体来说,您是否尝试运行“docker run -it centos /bin/sh”并在其中运行“yum -y install httpd”?它至少会让你看到错误。
-
您的主机是否在公司代理或类似的东西后面运行?
-
@Uberhumus - 我尝试使用 root 访问权限运行 yum update -y。由于我正在创建 docker 文件并需要构建它,我是否应该将“docker run -it centos /bin/sh”放入 docker 文件中。或者您希望我在构建 Dockerfile 之前将其作为命令行运行。
-
@agentsmith - 这是我的个人笔记本电脑,所以没有公司防火墙或任何代理。我正在运行 Windows 10 作为通过 OracleVM 运行 CentOS 的主机。因此,与我的主机 Windows 连接的 Wifi 相同,它也被用于为我的虚拟机提供 Internet 连接。
-
@arijhit,你能试试这些并报告结果吗:在运行的 CentOS docker 中尝试 ping 8.8.8.8 如果可行,尝试 'yum check-update' 然后 'yum -y install httpd'
标签: dockerfile yum centos8