经由Docker发布的端口 - 无法连接

3
我正在尝试在Docker容器中运行 jupyter/jupyter-notebook
#!/bin/bash

docker run --detach --name jupyter \
  --publish 4000:8888 \
  --volume /root/docker/jupyter:/home/jovyan \
  jupyter/tensorflow-notebook start-notebook.sh --NotebookApp.password='sha1:XXXXXXX...'

然而,似乎出现了一些问题。
root@vmd16038:~/docker# wget 0.0.0.0:4000
--2016-12-30 11:55:32--  http://0.0.0.0:4000/
Connecting to 0.0.0.0:4000... connected.
HTTP request sent, awaiting response... Read error (Connection reset by peer) in headers.
Retrying.

不过,当我从容器内部执行时它是有效的。

root@vmd16038:~/docker# docker exec -it jupyter wget localhost:8888
--2016-12-30 10:58:54--  http://localhost:8888/
Resolving localhost (localhost)... ::1, 127.0.0.1
Connecting to localhost (localhost)|::1|:8888... connected.
HTTP request sent, awaiting response... 302 Found
Location: /tree [following]
--2016-12-30 10:58:54--  http://localhost:8888/tree
Reusing existing connection to [localhost]:8888.
HTTP request sent, awaiting response... 302 Found
Location: /login?next=%2Ftree [following]
--2016-12-30 10:58:54--  http://localhost:8888/login?next=%2Ftree
Reusing existing connection to [localhost]:8888.
HTTP request sent, awaiting response... 200 OK
Length: 5176 (5.1K) [text/html]
Saving to: ‘index.html’

index.html                       100%[==========================================================>]   5.05K  --.-KB/s   in 0s     

2016-12-30 10:58:54 (562 MB/s) - ‘index.html’ saved [5176/5176]
<输出docker ps命令结果>
65edf25e4de4        jupyter/tensorflow-notebook    "tini -- start-notebo"   6 minutes ago       Up 6 minutes        0.0.0.0:4000->8888/tcp            

这里可能出了什么问题?我对Docker还很陌生,不知道如何调试这个问题。


更新:根据 @cen 的要求,docker inspect jupyter

[
    {
        "Id": "af3f5185f0a84f151fa3889eb0f6133403b9c85838d4027a256f07b904ea9f36",
        "Created": "2016-12-30T11:02:33.95435373Z",
        "Path": "tini",
        "Args": [
            "--",
            "start-notebook.sh",
            "--NotebookApp.password=sha1:XXXXXXXXX..."
        ],
        "State": {
            "Status": "running",
            "Running": true,
            "Paused": false,
            "Restarting": false,
            "OOMKilled": false,
            "Dead": false,
            "Pid": 21923,
            "ExitCode": 0,
            "Error": "",
            "StartedAt": "2016-12-30T11:02:34.250859339Z",
            "FinishedAt": "0001-01-01T00:00:00Z"
        },
        "Image": "sha256:6f160f85eb62403786a30639eedd63412e8381a10d492a378c07f220e9332336",
        "ResolvConfPath": "/var/lib/docker/containers/af3f5185f0a84f151fa3889eb0f6133403b9c85838d4027a256f07b904ea9f36/resolv.conf",
        "HostnamePath": "/var/lib/docker/containers/af3f5185f0a84f151fa3889eb0f6133403b9c85838d4027a256f07b904ea9f36/hostname",
        "HostsPath": "/var/lib/docker/containers/af3f5185f0a84f151fa3889eb0f6133403b9c85838d4027a256f07b904ea9f36/hosts",
        "LogPath": "/var/lib/docker/containers/af3f5185f0a84f151fa3889eb0f6133403b9c85838d4027a256f07b904ea9f36/af3f5185f0a84f151fa3889eb0f6133403b9c85838d4027a256f07b904ea9f36-json.log",
        "Name": "/jupyter",
        "RestartCount": 0,
        "Driver": "aufs",
        "MountLabel": "",
        "ProcessLabel": "",
        "AppArmorProfile": "",
        "ExecIDs": null,
        "HostConfig": {
            "Binds": [
                "/root/docker/jupyter:/home/jovyan"
            ],
            "ContainerIDFile": "",
            "LogConfig": {
                "Type": "json-file",
                "Config": {}
            },
            "NetworkMode": "default",
            "PortBindings": {
                "8888/tcp": [
                    {
                        "HostIp": "127.0.0.1",
                        "HostPort": "4000"
                    }
                ]
            },
            "RestartPolicy": {
                "Name": "no",
                "MaximumRetryCount": 0
            },
            "AutoRemove": false,
            "VolumeDriver": "",
            "VolumesFrom": null,
            "CapAdd": null,
            "CapDrop": null,
            "Dns": [],
            "DnsOptions": [],
            "DnsSearch": [],
            "ExtraHosts": null,
            "GroupAdd": null,
            "IpcMode": "",
            "Cgroup": "",
            "Links": null,
            "OomScoreAdj": 0,
            "PidMode": "",
            "Privileged": false,
            "PublishAllPorts": false,
            "ReadonlyRootfs": false,
            "SecurityOpt": null,
            "UTSMode": "",
            "UsernsMode": "",
            "ShmSize": 67108864,
            "Runtime": "runc",
            "ConsoleSize": [
                0,
                0
            ],
            "Isolation": "",
            "CpuShares": 0,
            "Memory": 0,
            "CgroupParent": "",
            "BlkioWeight": 0,
            "BlkioWeightDevice": null,
            "BlkioDeviceReadBps": null,
            "BlkioDeviceWriteBps": null,
            "BlkioDeviceReadIOps": null,
            "BlkioDeviceWriteIOps": null,
            "CpuPeriod": 0,
            "CpuQuota": 0,
            "CpusetCpus": "",
            "CpusetMems": "",
            "Devices": [],
            "DiskQuota": 0,
            "KernelMemory": 0,
            "MemoryReservation": 0,
            "MemorySwap": 0,
            "MemorySwappiness": -1,
            "OomKillDisable": false,
            "PidsLimit": 0,
            "Ulimits": null,
            "CpuCount": 0,
            "CpuPercent": 0,
            "IOMaximumIOps": 0,
            "IOMaximumBandwidth": 0
        },
        "GraphDriver": {
            "Name": "aufs",
            "Data": null
        },
        "Mounts": [
            {
                "Source": "/root/docker/jupyter",
                "Destination": "/home/jovyan",
                "Mode": "",
                "RW": true,
                "Propagation": "rprivate"
            }
        ],
        "Config": {
            "Hostname": "af3f5185f0a8",
            "Domainname": "",
            "User": "jovyan",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "ExposedPorts": {
                "8888/tcp": {}
            },
            "Tty": false,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": [
                "PATH=/opt/conda/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
                "DEBIAN_FRONTEND=noninteractive",
                "CONDA_DIR=/opt/conda",
                "SHELL=/bin/bash",
                "NB_USER=jovyan",
                "NB_UID=1000",
                "HOME=/home/jovyan",
                "LC_ALL=en_US.UTF-8",
                "LANG=en_US.UTF-8",
                "LANGUAGE=en_US.UTF-8",
                "XDG_CACHE_HOME=/home/jovyan/.cache/"
            ],
            "Cmd": [
                "start-notebook.sh",
                "--NotebookApp.password=sha1:XXXXXXXXX..."
            ],
            "Image": "jupyter/tensorflow-notebook",
            "Volumes": null,
            "WorkingDir": "/home/jovyan/work",
            "Entrypoint": [
                "tini",
                "--"
            ],
            "OnBuild": null,
            "Labels": {}
        },
        "NetworkSettings": {
            "Bridge": "",
            "SandboxID": "1101443ef853ceecafa98b81ddf5598a35af6c68dbb76ec54dcbe3d11453c467",
            "HairpinMode": false,
            "LinkLocalIPv6Address": "",
            "LinkLocalIPv6PrefixLen": 0,
            "Ports": {
                "8888/tcp": [
                    {
                        "HostIp": "127.0.0.1",
                        "HostPort": "4000"
                    }
                ]
            },
            "SandboxKey": "/var/run/docker/netns/1101443ef853",
            "SecondaryIPAddresses": null,
            "SecondaryIPv6Addresses": null,
            "EndpointID": "331bbeaa9e0d5b447e76d87224f2685b4fdcf33ef96f3d1918093f8c3760a8e1",
            "Gateway": "172.17.0.1",
            "GlobalIPv6Address": "",
            "GlobalIPv6PrefixLen": 0,
            "IPAddress": "172.17.0.5",
            "IPPrefixLen": 16,
            "IPv6Gateway": "",
            "MacAddress": "02:42:ac:11:00:05",
            "Networks": {
                "bridge": {
                    "IPAMConfig": null,
                    "Links": null,
                    "Aliases": null,
                    "NetworkID": "a762e41b430703ebc04210030c60988c92fcd64aa0ab224e779f2523e51de1a3",
                    "EndpointID": "331bbeaa9e0d5b447e76d87224f2685b4fdcf33ef96f3d1918093f8c3760a8e1",
                    "Gateway": "172.17.0.1",
                    "IPAddress": "172.17.0.5",
                    "IPPrefixLen": 16,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "MacAddress": "02:42:ac:11:00:05"
                }
            }
        }
    }
]

使用netstat -nat | grep 4000命令

tcp        0      0 127.0.0.1:4000          0.0.0.0:*               LISTEN     

2
你能提供 docker inspectnetstat -nat | grep 4000 吗? - cen
1
Docker和端口似乎没问题。 "Connection reset by peer" 显然意味着HTTP服务器关闭了连接,这意味着您实际上已经连接到容器,但应用程序不喜欢您的请求中的某些内容。我不知道jupyter是什么,但也许它有一些连接限制,例如:拒绝所有不在本地主机上的连接?默认情况下,Postgres就是这样的一个例子。 - cen
谢谢@cen。看起来这是应用程序的问题。 - Niklas R
2个回答

0

0.0.0.0 表示它正在监听所有 IP 地址,它不是发送 HTTP 请求的有效目标。请在 Docker 主机上尝试以下操作。

$ wget localhost:4000

我得到了与 0.0.0.0:4000 相同的结果。 - Niklas R
看起来很奇怪。仔细再看一遍错误信息,内容如下。 - minamijoyo
在头部读取错误(连接被对等方重置)。这可能是HTTP级别的问题。使用“wget -S localhost:4000”命令查看HTTP响应头是什么? - minamijoyo

0

您正在使用错误的IP地址 wget 0.0.0.0:4000,请改用以下地址:

localhost:4000eth0(IP):4000


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接