FROM golang:1.9
WORKDIR /go/src/github.com/sohag1990/gingorm-master
COPY . .
docker build -t whoshakhawat/go-app .
build success
docker run -it whoshakhawat/go-app /bin/bash
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中,一切都很好。谢谢:)
答案 0 :(得分:0)
我得到了可能对其他人有用的解决方案。
通过/ 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/
处阅读文档