Can't connect to Docker containers on OSX

If you read through Docker's Installation on Mac OS X you'll see that on OSX, Docker containers don't run on the host machine itself:

In a Docker installation on Linux, your physical machine is both the localhost and the Docker host. In networking, localhost means your computer. The Docker host is the computer on which the containers run.

On a typical Linux installation, the Docker client, the Docker daemon, and any containers run directly on your localhost. This means you can address ports on a Docker container using standard localhost addressing such as localhost:8000 or 0.0.0.0:8376.

[...]

In an OS X installation, the docker daemon is running inside a Linux VM called default. The default is a lightweight Linux VM made specifically to run the Docker daemon on Mac OS X. The VM runs completely from RAM, is a small ~24MB download, and boots in approximately 5s.

In OS X, the Docker host address is the address of the Linux VM. When you start the VM with docker-machine it is assigned an IP address. When you start a container, the ports on a container map to ports on the VM. To see this in practice, work through the exercises on this page.

Indeed, opening a new Docker Quickstart Terminal, I see:

docker is configured to use the default machine with IP 192.168.99.100

And, opening http://192.168.99.100:8080 takes me to Shipyard. Success!


You can try and execute this command:

docker-machine ip default

it will return some thing like:

192.168.99.100

To get port number:

docker ps

Example output (scroll right to see port mapping):

CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES
113346425f20        springio/spring1    "sh -c 'java $JAVA_OP"   34 minutes ago      Up 34 minutes       0.0.0.0:8080->8080/tcp   pensive_kirch

To verify if it is working do:

curl 192.168.99.100:8080

Tags:

Docker

Macos