0

I tried to follow this question: How to connect to netcat running in docker container?

I have

C:\Users\Chloe\workspace\spinsci>docker container ls
CONTAINER ID        IMAGE               COMMAND                 CREATED             STATUS              PORTS                    NAMES
0df9daa8d8cc        b7bd807e363a        "/bin/sh -c /bin/ash"   9 seconds ago       Up 6 seconds        0.0.0.0:1300->1300/tcp   optimistic_newton

C:\Users\Chloe\workspace\spinsci>docker exec -it 0df9daa8d8cc /bin/ash
/ # nc -l -p 1300

On my host computer, I try to connect and it fails:

$ nc -vv localhost 1300
nc: connect to localhost port 1300 (tcp) failed: Connection refused
nc: connect to localhost port 1300 (tcp) failed: Connection refused

$ nc 127.0.0.1 1300
$ nc 0.0.0.0 1300
$ telnet localhost 1300
Trying ::1...
Connection failed: Connection refused
Trying 127.0.0.1...
telnet: Unable to connect to remote host: Connection refused

My Dockerfile is merely

FROM alpine:latest
EXPOSE 1300
CMD /bin/ash

Running docker inspect 0df9daa8d8cc yields

...
    "HostConfig": {
        "PortBindings": {
            "1300/tcp": [
                {
                    "HostIp": "",
                    "HostPort": "1300"
                }
            ]
        },
...
    "NetworkSettings": {
        "Ports": {
            "1300/tcp": [
                {
                    "HostIp": "0.0.0.0",
                    "HostPort": "1300"
                }
            ]
        },
...
        "Networks": {
                "Gateway": "172.17.0.1",
                "IPAddress": "172.17.0.2",

Using Docker Toolbox (Engine 19.03.5) because Windows 8.1.

Chloe
  • 25,162
  • 40
  • 190
  • 357

1 Answers1

1

Docker Toolbox runs docker in a linux virtual machine running in virtualbox. The VM has it's own virtual NIC with a different IP address. It should show up in the list of windows adapters in Control Panel (or with ipconfig), and by default the IP is in the 192.168.99.x subnet. So the right command on the host would be nc 192.168.99.x 1300 where x is whatever the real value from your running setup is.

  • I tried `nc 192.168.99.1 1300` and `nc 192.168.1.1 1300` but it didn't work. `...99.1` was `VirtualBox Host-Only Network #5` which was the same network adapter #2 in VirtualBox. – Chloe Feb 03 '20 at 18:16
  • Can you ping the virtual adapter? If not, double check your subnet masks on the host to make sure you can get to the 192.168.99 subnet from your physical adapter – CantankerousBullMoose Feb 03 '20 at 18:23
  • Yes `Reply from 192.168.99.1: bytes=32 time<1ms TTL=128` – Chloe Feb 03 '20 at 18:25