通过Docker发布的端口 - 无法连接

时间:2016-12-30 11:00:30

标签: docker

我试图在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 个答案:

答案 0 :(得分:0)

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

$ wget localhost:4000

答案 1 :(得分:0)

您使用了错误的IP地址wget 0.0.0.0:4000而不是使用

localhost:4000eth0(IP):4000