0

I am using docker toolbox, to setup:

  1. virtualbox default vm in Windows 10
  2. container running inside virtualbox vm

The problem is I cannot access the web service in the container.

here is some command I use:

# 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>

Now I tried to access with the following address, but all failed to load the web page:

  1. localhost:8000
  2. 192.168.99.100:8000 (the virtualbox vm's ip)
  3. 172.17.0.2:8000 (the container's ip)

Here are some command I used and their results:

$ 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"
                }
            }
        }
    }
]

docker toolbox also have a default configuration for "default" vm's network setting:

1: NAT

2: Host-only Adapter (Virtualbox Host-Only Ethernet Adapter #2).

I am new to docker toolbox, What should I do to access the webpage in the container? Could you please help me to diagnostic my problem?

user2262504
  • 7,057
  • 5
  • 18
  • 23
  • What error do you get? Check if there is a firewall that blocks the port. Also, try to access anything via the VM's IP. Something that is running outside a container, for example Python SimpleHTTPServer. – vempo May 27 '17 at 15:41
  • @vempo when I use ip:port to access the webpage, I found no response. and also no connection is print out in the container command terminal. how should I check the firewall? (whos firewall). By VM's IP, do you mean 192.168.99.100 above? I am using SimpleHTTPServer here. can you please guide me to diagnostic the problem? – user2262504 May 28 '17 at 00:02
  • So if you run SimpleHTTPServer in the VM outside a container, are you able to access it from the host machine? For example, http://192.168.99.100:8080 (the port you've configured). You first have to figure out where the problem is - host/VM or VM/container. – vempo May 28 '17 at 04:58

2 Answers2

0

If VM (Docker Host) is running Linux, try iptables -F & iptables -t nat -F and try again from Host-Only or Bridge Mode network from Windows, for Ex, if Host Only interface IP is 192.168.56.101 for VM, try that IP:8080 from Windows Physical Host.

  • I check the docker toolbox is running boot2docker images in the VM. In default, docker toolbox created a vm named "default", and network is configured to have both Adapter 1: NAT and Adapter 2: Host-only Adapter (Virtualbox Host-Only Ethernet Adapter #2). Could you please help to diagnostic the problem, I have no idea where to go next. – user2262504 May 28 '17 at 00:12
  • First check if the Host Only #2 gateway is reachable from VM. – Subodh Pachghare May 28 '17 at 05:39
0

I assume that you are asking about accessing web service from the host machine where Virtualbox is running.

As you would already know, you can access the webservice from the boot2docker Linux machine using localhost: or :.

To access the web service from your host machine, you can use the port forwarding functionality provided by Virtualbox. You can go to settings->Network->Port forwarding under the NAT adapter of the boot2docker machine and add port forwarding between boot2docker host port and windows machine port. For your example, you can say (hostip=127.0.0.1, host port=8000, guest port=8000). After this, you can access webserver using localhost:8000 or 127.0.0.1.8000 from your host machine.

Hope this helps.

Regards Sreenivas

Sreeni
  • 748
  • 5
  • 6
  • Hi ! It would be better if you checkout [How to create a Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve) for future endeavor at Stack overflow. -Thank you – Momin May 28 '17 at 08:25