Tho*_*rig 21 ubuntu networking ping docker
我有一个正在运行的Docker容器(来自此图像).据我所知,容器似乎正在正常运行(日志文件看起来很好,可以通过SSH连接到容器并在其中使用SQLPlus).但是,我无法从主机连接到容器.
我像这样启动容器:
sudo docker run -d -p 49160:22 -p 49161:1521 -p 49162:8080 alexeiled/docker-oracle-xe-11g
Run Code Online (Sandbox Code Playgroud)
我通过这个检查了端口绑定:
$ sudo docker port <container> 8080
0.0.0.0:49162
Run Code Online (Sandbox Code Playgroud)
当我做一个时,sudo docker inspect <container>
我得到了其他人:
"NetworkSettings": {
"IPAddress": "172.17.0.2",
"IPPrefixLen": 16,
"Gateway": "172.17.42.1",
"Bridge": "docker0",
"PortMapping": null,
"Ports": {
"1521/tcp": [
{
"HostIp": "0.0.0.0",
"HostPort": "49161"
}
],
"22/tcp": [
{
"HostIp": "0.0.0.0",
"HostPort": "49160"
}
],
"8080/tcp": [
{
"HostIp": "0.0.0.0",
"HostPort": "49162"
}
]
}
},
Run Code Online (Sandbox Code Playgroud)
当我尝试ping容器时,容器响应:
$ ping 172.17.0.2
PING 172.17.0.2 (172.17.0.2) 56(84) bytes of data.
64 bytes from 172.17.0.2: icmp_req=1 ttl=64 time=0.138 ms
64 bytes from 172.17.0.2: icmp_req=2 ttl=64 time=0.132 ms
Run Code Online (Sandbox Code Playgroud)
但我无法从我的主机(Windows)连接到Docker容器.我在Ubuntu 12.04虚拟机中运行Docker(在Windows上的VirtualBox中).我不确定Docker,Linux VM或VirtualBox是否存在问题.我在VirtualBox中转发了一堆端口:
这是以下结果sudo netstat -tpla
:
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 *:sunrpc *:* LISTEN 542/rpcbind
tcp 0 0 *:ssh *:* LISTEN 1661/sshd
tcp 0 0 *:51201 *:* LISTEN 831/rpc.statd
tcp 0 80 docker:ssh 10.0.2.2:62220 ESTABLISHED 1902/sshd: vagrant
tcp6 0 0 [::]:49160 [::]:* LISTEN 2388/docker
tcp6 0 0 [::]:49161 [::]:* LISTEN 2388/docker
tcp6 0 0 [::]:56105 [::]:* LISTEN 831/rpc.statd
tcp6 0 0 [::]:49162 [::]:* LISTEN 2388/docker
tcp6 0 0 [::]:sunrpc [::]:* LISTEN 542/rpcbind
tcp6 0 0 [::]:ssh [::]:* LISTEN 1661/sshd
Run Code Online (Sandbox Code Playgroud)
知道为什么我无法从Windows连接到我的(运行)Docker容器吗?
Jir*_*iri 12
更新:
您的配置对我来说似乎没问题,但我认为端口49160-49162
应该绑定到IPv4接口而不是IPv6.我用谷歌搜索了这个,似乎你在docker中遇到了一个开放的bug:
我看到你的问题的两个解决方案:
172.17.42.1:49162:8080
编辑前回答:
你不能ping端口.Ping正在使用ICMP协议.
如果您无法连接到已发布的端口,您可以检查docker容器中的特定服务是否绑定到正确的网络接口(fe 0.0.0.0
)而不是localhost
.您可以检查容器中的所有侦听端口:netstat -tpla
.
归档时间: |
|
查看次数: |
39991 次 |
最近记录: |