Docker在容器中侦听但不在外部应答,为什么? [英] Docker listening in container but not answering outside, why?

查看:75
本文介绍了Docker在容器中侦听但不在外部应答,为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在其说明中有一个使用 EXPOSE 8000构建的码头集装箱。我是这样开始程序的:

I have a docker container built with "EXPOSE 8000" among its instructions. I started the process like this:

sudo docker run -t -i -P imagename

容器中的进程正在侦听8000。

The process in the container is listening on 8000.

# netstat -a
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State      
tcp        0      0 localhost:8000          *:*                     LISTEN     
Active UNIX domain sockets (servers and established)
Proto RefCnt Flags       Type       State         I-Node   Path
# 

在主机上(即容器外部),我看到端口49164绑定到容器端口8000:

On the host (i.e., outside the container), I see that port 49164 is bound to container port 8000:

[S-22]jeff@siegfried:~ $ sudo docker ps 
CONTAINER ID        IMAGE                      COMMAND             CREATED             STATUS              PORTS                     NAMES
0b0e333c6ec9        lkz:latest                 "/bin/bash"         About an hour ago   Up 6 minutes        0.0.0.0:49164->8000/tcp   lkxyz__2015-01-18_202737   
[S-22]jeff@siegfried:~ $ 

Inded, docker inspect 说(除其他外)

Inded, docker inspect says (among other things)

"NetworkSettings": {
    "Bridge": "docker0",
    "Gateway": "172.17.42.1",
    "IPAddress": "172.17.0.16",
    "IPPrefixLen": 16,
    "PortMapping": null,
    "Ports": {
        "8000/tcp": [
            {
                "HostIp": "0.0.0.0",
                "HostPort": "49164"
            }
        ]
    }
},

但是,我无法与容器交谈。在外面,

And yet, I can't talk to the container. Outside,

[S-22]jeff@siegfried:~ $ telnet localhost 49164
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
Connection closed by foreign host.
1,[S-22] jeff@siegfried:~ $ 

在里面,

# telnet localhost 8000
Trying ::1...
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
GET /

[18/Jan/2015 23:00:59] "GET /" 200 4066
<!DOCTYPE html>
<html>
<head>
...

我希望远程登录到49164的telnet返回html作为

I would expect the telnet to 49164 on the outside to return html as it does on the inside.

有什么建议吗?

推荐答案

您可能想让您正在容器中运行的服务监听 0.0.0.0 而不是 127.0.0.1

You probably want to have the service you're running in the container to listen on 0.0.0.0 rather than 127.0.0.1

这篇关于Docker在容器中侦听但不在外部应答,为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆