docker - 从 ubuntu 18.04 升级到 18.10 后,docker 容器内没有互联网连接

标签 docker go dockerfile ubuntu-18.04

将主机 ubuntu 18.04 升级到 18.10 后,ping 到 google 无法正常工作

我的 docker 文件

FROM golang:1.9
WORKDIR /go/src/github.com/sohag1990/gingorm-master
COPY . .

docker 构建命令

docker build -t whoshakhawat/go-app .
build success

使用/bin/bash 运行容器

docker run -it whoshakhawat/go-app /bin/bash

docker 容器内的 ping 命令

root@62ba0502a1c6:/# ping google.com
ping: google.com: Temporary failure in name resolution
root@62ba0502a1c6:/# ping github.com
ping: github.com: Temporary failure in name resolution

在 Ubuntu-18.04 中一切都很好。谢谢:)

最佳答案

我得到了可能对其他人有帮助的解决方案。

通过/bin/bash访问正在运行的容器

docker run --network=host -it whoshakhawat/go-app /bin/bash

--network=host 消除了 docker 主机和 docker 容器之间的任何网络隔离。

现在 docker 容器内的 ping 命令工作正常。

root@62ba0502a1c6:/# ping github.com
PING github.com (192.30.255.112) 56(84) bytes of data.
64 bytes from lb-192-30-255-112-sea.github.com (192.30.255.112): icmp_seq=1 ttl=47 time=259 ms

这里 Docker 容器和主机都在同一个网络中对齐。 在此处阅读文档 https://docs.docker.com/network/host/

关于docker - 从 ubuntu 18.04 升级到 18.10 后,docker 容器内没有互联网连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52956291/

相关文章:

ruby - 更新 gem 时 Docker 包安装缓存问题

go - 如何在golang中获取重定向的URL

docker - 错误 : cannot start nginx as networking would not start on alpine docker image

linux - Docker 从部分图像中理解

docker - docker-compose卷不起作用

docker - Github Action docker 缓存

docker - Docker hello-world给出以下错误:容器/hello:无此类文件或目录“:未知

ssl - 从私钥中提取公钥

go - 使用 GORM 选择相关字段

docker - 我们如何在 Cassandra Dockerfile 中运行 flyway/migrations 脚本?