Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't connect to Docker containers on OSX

Tags:

docker

macos

I'm new to Docker, and I can't seem to connect to any containers.

I installed Docker Toolbox. Now I'm trying to get Shipyard to work. I followed the steps inside of a Docker Quickstart Terminal. The instructions say:

Once deployed, the script will output the URL to connect along with credential information.

The Shipyard installer ended with:

Shipyard available at http://10.0.2.15:8080
Username: [elided] Password: [elided]

However, I went to http://10.0.2.15:8080 on my browser and it didn't connect.

In another Docker Quickstart Terminal, I did a docker ps to see what the container was and to get its IP Address and I got:

$ docker inspect a4755 | grep IPAddress
            "SecondaryIPAddresses": null,
            "IPAddress": "172.17.0.8",
                    "IPAddress": "172.17.0.8",

I'm not sure why the IP was different, but I tried to connect to http://172.17.0.8:8080 and this didn't work either. http://localhost:8080 also failed.

This also happened when I tried to run docker-gunicorn-nginx - everything started, but I couldn't connect to the machine.

What gives?

like image 418
Claudiu Avatar asked Mar 08 '16 21:03

Claudiu


People also ask

Can't connect to the Docker daemon Mac?

On macOS the docker binary is only a client and you cannot use it to run the docker daemon, because Docker daemon uses Linux-specific kernel features, therefore you can't run Docker natively in OS X. So you have to install docker-machine in order to create VM and attach to it.

How do I connect to a Docker container?

To connect to a container using plain docker commands, you can use docker exec and docker attach . docker exec is a lot more popular because you can run a new command that allows you to spawn a new shell. You can check processes, files and operate like in your local environment.


1 Answers

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!

like image 157
Claudiu Avatar answered Sep 21 '22 06:09

Claudiu