2017-05-27 83 views
0

我使用泊塢窗工具箱,設置:泊塢窗機(VirtualBox的VM)的出口集裝箱港口主辦機失敗

  1. VirtualBox的默認虛擬機在Windows 10
  2. 容器的VirtualBox虛擬機內運行

問題是我無法訪問容器中的Web服務。

這裏是一些命令我使用:

# start up the web service 
docker run -p 8000:8000 -p 9000:9000 -t -i xxx/myweb /bin/bash -l -c '/root/myweb/demos/web/start-servers.sh' 

# terminal print after above cmd 
Starting the HTTP TLS server on port 8000 
and the Secure WebSocket server on port 9000. 

Access the demo through the HTTP server in your browser. 
If you're running on the same computer outside of Docker, use https://localhost:8000 
If you're running on the same computer with Docker, find the IP 
address of the Docker container and use https://<docker-ip>:8000. 
If you're running on a remote computer, find the IP address 
and use https://<remote-ip>:8000. 

WARNING: Chromium will warn on self-signed certificates. Please accept the certificate 
and reload the app. 

WebSocket Server: Logging to '/tmp/openface.websocket.log' 

2017-05-27 15:10:13+0000 [-] Log opened. 
2017-05-27 15:10:13+0000 [-] WebSocketServerFactory (TLS) starting on 9000 
2017-05-27 15:10:13+0000 [-] Starting factory <autobahn.twisted.websocket.WebSocketServerFactory object at 0x7f00ef9f5c90> 

現在我試着用下面的地址來訪問,但都未能加載網頁:

  1. 本地主機:8000
  2. 192.168 .99.100:8000(virtualbox虛擬機的ip)
  3. 172.17.0.2:8000(容器的ip)

下面是一些命令我使用及其結果:

$ docker-machine config 
--tlsverify 
--tlscacert="C:\\Users\\AIT\\.docker\\machine\\machines\\default\\ca.pem" 
--tlscert="C:\\Users\\AIT\\.docker\\machine\\machines\\default\\cert.pem" 
--tlskey="C:\\Users\\AIT\\.docker\\machine\\machines\\default\\key.pem" 
-H=tcp://192.168.99.100:2376 

$ docker ps 
CONTAINER ID  IMAGE    COMMAND     CREATED    STATUS    PORTS               NAMES 
5896815b991d  xxx/myweb "/bin/bash -l -c /..." 12 minutes ago  Up 12 minutes  192.168.99.100:8000->8000/tcp, 192.168.99.100:9000->9000/tcp thirsty_wiles 

$ docker inspect thirsty_wiles 
[ 
    { 
     "Id": "5896815b991d394753b5eabdd4fe7967e2e4bd65791ffe7fa1d3e82486c9f050", 
     "Created": "2017-05-27T15:10:12.172475859Z", 
     "Path": "/bin/bash", 
     "Args": [ 
      "-l", 
      "-c", 
      "/root/myweb/demos/web/start-servers.sh" 
     ], 
     "State": { 
      "Status": "running", 
      "Running": true, 
      "Paused": false,    "Pid": 2753, 
      "ExitCode": 0, 
      "Error": "", 
      "StartedAt": "2017-05-27T15:10:12.294120929Z", 
      "FinishedAt": "0001-01-01T00:00:00Z" 
     }, 
     "Image": "sha256:3c9f00308ef150eef9d50576245df69234437a4360684f9b262a284f50dc15d7", 
     "ResolvConfPath": "/mnt/sda1/var/lib/docker/containers/5896815b991d394753b5eabdd4fe7967e2e4bd65791ffe7fa1d3e82486c9f050/resolv.conf", 
     "HostnamePath": "/mnt/sda1/var/lib/docker/containers/5896815b991d394753b5eabdd4fe7967e2e4bd65791ffe7fa1d3e82486c9f050/hostname", 
     "HostsPath": "/mnt/sda1/var/lib/docker/containers/5896815b991d394753b5eabdd4fe7967e2e4bd65791ffe7fa1d3e82486c9f050/hosts", 
     "LogPath": "/mnt/sda1/var/lib/docker/containers/5896815b991d394753b5eabdd4fe7967e2e4bd65791ffe7fa1d3e82486c9f050/5896815b991d394753b5eabdd4fe7967e2e4bd65791ffe7fa1d3e82486c9f050-json.log", 
     "Name": "/thirsty_wiles", 
     "RestartCount": 0, 
     "Driver": "aufs", 
     "MountLabel": "", 
     "ProcessLabel": "", 
     "AppArmorProfile": "", 
     "ExecIDs": null, 
     "HostConfig": { 
      "Binds": null, 
      "ContainerIDFile": "", 
      "LogConfig": { 
       "Type": "json-file", 
       "Config": {} 
      }, 
      "NetworkMode": "default", 
      "PortBindings": { 
       "8000/tcp": [ 
        { 
         "HostIp": "192.168.99.100", 
         "HostPort": "8000" 
        } 
       ], 
       "9000/tcp": [ 
        { 
         "HostIp": "192.168.99.100", 
         "HostPort": "9000" 
        } 
       ] 
      }, 
      "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": [ 
       30, 
       120 
      ], 
      "Isolation": "", 
      "CpuShares": 0, 
      "Memory": 0, 
      "NanoCpus": 0, 
      "CgroupParent": "", 
      "BlkioWeight": 0, 
      "BlkioWeightDevice": null, 
      "BlkioDeviceReadBps": null, 
      "BlkioDeviceWriteBps": null, 
      "BlkioDeviceReadIOps": null, 
      "BlkioDeviceWriteIOps": null, 
      "CpuPeriod": 0, 
      "CpuQuota": 0, 
      "CpuRealtimePeriod": 0, 
      "CpuRealtimeRuntime": 0, 
      "CpusetCpus": "", 
      "CpusetMems": "", 
      "Devices": [], 
      "DeviceCgroupRules": null, 
      "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": { 
      "Data": null, 
      "Name": "aufs" 
     }, 
     "Mounts": [], 
     "Config": { 
      "Hostname": "5896815b991d", 
      "Domainname": "", 
      "User": "", 
      "AttachStdin": true, 
      "AttachStdout": true, 
      "AttachStderr": true, 
      "ExposedPorts": { 
       "8000/tcp": {}, 
       "9000/tcp": {} 
      }, 
      "Tty": true, 
      "OpenStdin": true, 
      "StdinOnce": true, 
      "Env": [ 
       "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" 
      ], 
      "Cmd": [ 
       "/bin/bash", 
       "-l", 
       "-c", 
       "/root/myweb/demos/web/start-servers.sh" 
      ], 
      "Image": "xxx/myweb", 
      "Volumes": null, 
      "WorkingDir": "", 
      "Entrypoint": null, 
      "OnBuild": null, 
      "Labels": {} 
     }, 
     "NetworkSettings": { 
      "Bridge": "", 
      "SandboxID": "97f5c2894d9a6977723e3a54db77f7ff81150d8447722147a0d561a193d4caeb", 
      "HairpinMode": false, 
      "LinkLocalIPv6Address": "", 
      "LinkLocalIPv6PrefixLen": 0, 
      "Ports": { 
       "8000/tcp": [ 
        { 
         "HostIp": "192.168.99.100", 
         "HostPort": "8000" 
        } 
       ], 
       "9000/tcp": [ 
        { 
         "HostIp": "192.168.99.100", 
         "HostPort": "9000" 
        } 
       ] 
      }, 
      "SandboxKey": "/var/run/docker/netns/97f5c2894d9a", 
      "SecondaryIPAddresses": null, 
      "SecondaryIPv6Addresses": null, 
      "EndpointID": "2f62e7e113d8ec9f0c6760f618f53f43821c469b3c461b7447011737ee768c65", 
      "Restarting": false, 
      "OOMKilled": false, 
      "Dead": false, 

      "Gateway": "172.17.0.1", 
      "GlobalIPv6Address": "", 
      "GlobalIPv6PrefixLen": 0, 
      "IPAddress": "172.17.0.2", 
      "IPPrefixLen": 16, 
      "IPv6Gateway": "", 
      "MacAddress": "02:42:ac:11:00:02", 
      "Networks": { 
       "bridge": { 
        "IPAMConfig": null, 
        "Links": null, 
        "Aliases": null, 
        "NetworkID": "188e40f0cb38ff9be5f053cffdf5e97c22bfed8f7ee93c685178d0c9748a032c", 
        "EndpointID": "2f62e7e113d8ec9f0c6760f618f53f43821c469b3c461b7447011737ee768c65", 
        "Gateway": "172.17.0.1", 
        "IPAddress": "172.17.0.2", 
        "IPPrefixLen": 16, 
        "IPv6Gateway": "", 
        "GlobalIPv6Address": "", 
        "GlobalIPv6PrefixLen": 0, 
        "MacAddress": "02:42:ac:11:00:02" 
       } 
      } 
     } 
    } 
] 

碼頭工人的工具箱也有一個 「默認」 的虛擬機的網絡設置默認配置:

1:NAT

2:HOST- (僅限Virtualbox主機以太網適配器#2)。

我是新來的碼頭工具箱,我該怎麼做才能訪問容器中的網頁?你能幫我診斷我的問題嗎?

+0

你會得到什麼錯誤?檢查是否有阻止端口的防火牆。另外,嘗試通過虛擬機的IP訪問任何東西。在容器外運行的東西,例如Python SimpleHTTPServer。 – vempo

+0

@vempo當我使用ip:port訪問網頁時,我發現沒有任何迴應。並且在集裝箱命令終端中也不打印連接。我應該如何檢查防火牆? (whos防火牆)。通過VM的IP,你的意思是192.168.99.100以上?我在這裏使用SimpleHTTPServer。你能指導我診斷問題嗎? – user2262504

+0

因此,如果您在容器外部的VM中運行SimpleHTTPServer,是否可以從主機訪問它?例如,http://192.168.99.100:8080(您配置的端口)。您首先必須找出問題所在 - 主機/虛擬機或虛擬機/容器。 – vempo

回答

0

如果VM(泊塢主機)運行Linux,嘗試iptables -F & iptables -t nat -F和僅主機或橋接模式網絡從Windows再試一次,防爆,如果主機網卡的IP是192.168.56.101的虛擬機,嘗試IP :來自Windows物理主機的8080。

+0

我檢查了docker工具箱正在虛擬機中運行boot2docker映像。默認情況下,docker工具箱創建一個名爲「default」的虛擬機,並將網絡配置爲兼容適配器1:NAT和適配器2:僅主機適配器(僅限Virtualbox主機以太網適配器2)。你能否幫助診斷問題,我不知道下一步該去哪裏。 – user2262504

+0

首先檢查Host Only#2網關是否可以從VM訪問。 –

0

我假定您正在詢問有關從運行Virtualbox的主機訪問Web服務的問題。如您所知,您可以使用localhost:或:從boot2docker Linux機器訪問webservice。

要從主機訪問Web服務,您可以使用Virtualbox提供的端口轉發功能。您可以轉到boot2docker機器的NAT適配器下的設置 - >網絡 - >端口轉發,並在boot2docker主機端口和Windows機器端口之間添加端口轉發。 對於您的示例,您可以說(hostip = 127.0.0.1,主機端口= 8000,訪客端口= 8000)。在此之後,您可以從主機使用localhost:8000或127.0.0.1.8000訪問Web服務器。

希望這會有所幫助。

關注 斯林尼瓦斯

+0

嗨!如果您結帳[如何創建一個最小化,完整和可驗證的示例](http://stackoverflow.com/help/mcve),以便將來在堆棧溢出時進行嘗試,那將會更好。 -謝謝 – Momin

相關問題