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

将主机ubuntu 18.04升级到18.10后,

ping到Google无法正常工作</ h1>

我的docker文件</ h2>

  FROM golang:1.9 
WORKDIR /go/src/github.com/sohag1990/gingorm-master
COPY。 。
</ code> </ pre>

docker build命令</ h2>

  docker build -t whoshakhawat / go-app。
构建成功
</ code> </ pre>

使用/ bin / bash运行容器</ h2>

  docker run -it whoshakhawat / go-app / bin / bash \  n </ code> </ pre> 

ping命令在Docker容器内</ h2>

  root @ 62ba0502a1c6:/#ping google.com 
ping:google。 com:名称解析暂时失败
root @ 62ba0502a1c6:/#ping github.com
ping:github.com:名称解析暂时失败
</ code> </ pre>

一切都很好 在Ubuntu-18.04中。 谢谢:)</ p>
</ div>

展开原文

原文

ping to google not working after upgrade host machine ubuntu 18.04 to 18.10

my docker file

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

docker build command

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

running container using /bin/bash

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

ping command inside docker container

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

Everything was fine when it was in Ubuntu-18.04. Thanks:)

dongshuo2752
dongshuo2752 您应该将8.8.8.8替换为google.com,例如ping8.8.8.8
一年多之前 回复
doupa2871
doupa2871 究竟该怎么做?你能描述一下吗?谢谢
一年多之前 回复
douyin7829
douyin7829 似乎是DNS问题,您是否尝试过使用IP?(示例:8.8.8.8)
一年多之前 回复

1个回答



我得到了可能对其他人有用的解决方案。</ p>

通过/访问访问运行中的容器 bin / bash </ p>

  docker run --network = host -it whoshakhawat / go-app / bin / bash 
</ code> </ pre>

< p>-network = host消除了docker主机与docker容器之间的所有网络隔离。</ p>

现在docker容器中的ping命令可以正常工作。</ p>

  root @ 62ba0502a1c6:/#ping github.com 
PING github.com(192.30.255.112)56(84)字节数据。
64字节来自lb-192-30-255-112- sea.github.com(192.30.255.112):icmp_seq = 1 ttl = 47 time = 259 ms
</ code> </ pre>

此处Docker容器和主机均在同一位置对齐
在此处阅读文档 https://docs.docker.com/network/host/ </ p>
</ div>

展开原文

原文

I got the solution that may be helpful for someone else.

Accessing running container through /bin/bash

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

The --network=host takes out any network isolation between the docker host and the docker containers.

Now ping command inside the docker container is working fine.

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

Here Docker container and Host machine both are aligned in the same network. Read Documentation here https://docs.docker.com/network/host/

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐