一,问题描述。在docker的容器中不能连接网络,无法ping 8.8.8.8。

1,安装镜像

 docker pull centos:7

 2,查看镜像

 docker images 

 3,使用新安装的centos:7镜像创建容器

 docker run -d -i -t <IMAGE ID> /bin/bash

 4,查看已经创建的容器

 docker ps -a 

 5,进入容器

 docker exec -it <CONTAINER ID> /bin/bash

 6,使用yum update更新包

 遇到One of the configured repositories failed (Unknown),and yum doesn't have enough cached data to continue. At this point the only safe thing yum can do is fail.

 7,尝试 ping 8.8.8.8,失败。

 二,解决办法。

1,新建docker时指定参数--network=host

docker run -itd --rm --network=host centos:7 /bin/bash

2,重复上面1.4,1.5,1.7步骤(可以ping 通 8.8.8.8和 www.baidu.com)。

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐