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

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

问题描述:

我试图在Docker容器中运行jupyter/jupyter-notebook通过Docker发布的端口 - 无法连接

#!/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...' 

但是,有些东西似乎出了问题。

[email protected]:~/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. 

它工作时,当我从容器内,但它。

[email protected]:~/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

你能提供'码头工人inspect'和'netstat的-nat | grep 4000'? – cen

+1

Docker和端口似乎很好。 “通过对等方重置连接”显然意味着HTTP服务器关闭了连接,这意味着您实际上已经连接到容器,但应用程序不喜欢您的请求。我不知道jupyter是什么,但也许它有一些连接限制,例如:拒绝不在本地主机上的所有连接? Postgres会是默认情况下的一个例子。 – cen

+0

谢谢@cen。这似乎是应用程序的问题。 –

0.0.0.0意味着它的所有IP地址听,它不是作为一个有效的目的地用于发送HTTP请求。请在Docker主机上尝试以下操作。

$ wget localhost:4000 
+0

我得到了与'0.0.0.0:4000'相同的结果。 –

+0

看起来很奇怪。仔细查看错误消息,如下所示 – minamijoyo

+0

'在头中读取错误(由对等方重置连接).'这是一个可能的HTTP级别问题。什么是带有'wget -S localhost:4000'的HTTP响应头? – minamijoyo

你正在使用错误的IP地址wget 0.0.0.0:4000,而不是用它

localhost:4000eth0(IP):4000