如何解决发出RUN命令时Dockerfile错误
我正在尝试学习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]
解决方法
亲爱的以下所有解决了我的问题。
firewall-cmd --permanent --zone=trusted --add-interface=docker0
firewall-cmd --reload
在这里找到它: https://forums.centos.org/viewtopic.php?f=54&t=74270
非常感谢这里的每个人...
,我尝试构建您的Dockerfile,尽管有另一个错误,但我也遇到了错误。
以下分别是适用于CentOS 7和CentOS 8的Dockerfile:
FROM centos:7
RUN yum -y install httpd
EXPOSE 80
ENTRYPOINT [ "/usr/sbin/httpd" ]
CMD [ "-D","FOREGROUND"]
和
FROM centos:8
RUN yum clean all && \
yum -y update && \
yum -y install httpd
EXPOSE 80
ENTRYPOINT [ "/usr/sbin/httpd" ]
CMD [ "-D","FOREGROUND"]
让我知道其中任何一种对您都有用。
编辑:
如果需要,我会放入预制的图像here。
编辑2:
如果上述Dockerfile没有为您构建,则很可能是Docker的DNS问题。请按照this article中的步骤操作,以验证该假设并可能解决问题。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。