Can't connect to Docker containers on OSX - 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?

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

Related

linux container running on windows host -- access to host docker

I have an ubuntu container running on docker for windows. How can I give it access to the docker daemon that is running on my windows host?
Note: I am not trying to run docker-in-docker, i.e., inside my container, docker ps should show containers running on the host machine's docker daemon. If my host machine was running linux, this would be achieved by mounting /var/run/docker.sock inside the container -- is there a similar technique when the host machine runs windows?
This is my docker destkop version: Docker Desktop 4.12.0 (85629) is currently the newest version available.
You can expose the daemon via TCP socket, it's a setting under General

Docker Desktop on Mac issue with ssh to centos container on localhost

I know there are similar questions on the SO but many of the suggestions have not worked for me. I'm running Docker Desktop for Mac and I startup a docker container I've built that has ssh configured and running (I use these to connect to AWS, Azure etc). I startup the container with something like (the ubc/jlbase/jlbase image has ssh configure... and the following all works on a linux machine with docker0 network in place)
docker run -P --name test -d ubc/jlbase/jlbase
docker inspect test |grep IP
ping -c *the_ip_from_above*
does not connect. From what I can find, this is a known issue with Docker on Mac... but the help and links I've found don't seem to solve the problem. Can someone tell me what I've missed?
You can say that this is a know feature of Docker on Mac, not an issue. Docker on Mac is running on a virtual machine inside macOS, so the IP address you receive is the IP of the container inside the VM, not on macOS.
To address the two issues from the question:
How to enable ssh
To be able to ssh on your container, you will need to have the sshd running in the container and to publish the port 22. Check here to see how you can try this with a container that is already prepared
How to ping
Since the docker is running inside a VM, to be able to route traffic to the containers, you will need to setup the network layer to route the traffic. One approach is to create a tunnel between the VM and the machine.
This is much more complex setup and will require a help of a CNF (Conteinerized Network Function). One of the simplest CNF that was created just for this problem is soctun which creates a tunnel between the host and the docker network layer.

Docker localhost process not working on Windows

I am using Docker Quickstart Terminal to run a docker container. The container should work on port 8088 of localhost:
docker run -it --name myContainer -p 8088:8088
However, when I go to localhost:8088 or 127.0.0.1:8088 I can't find any process running.
This works on OSX.
Why is this not working on Windows?
I'm assuming you're using VirtualBox, since that's what is integrated with the Quickstart terminal.
The reason it doesn't work is that Windows isn't running your (Linux) containers natively, it's running them in a separate Linux-based VM. This VM is available under a different ip address than your "physical" machine, usually printed when you start the quickstart terminal:
This is the ip address you need to use in order to connect to published container ports.
One possibility is the kind of VM you are using : HyperV (Docker For Windows) or VirtualBox (Docker Toolbox).
If it is the later (which seems probable since you are using the Docker Quickstart Terminal), you need to port forward 8088 in order for your PC (localhost) to see it.
See "How do I configure docker compose to expose ports correctly?" as an example when using VirtualBox.
If localhost does not work, a docker-machine ip will show you the ip of the VM being executed.

Access Docker daemon Remote api on Docker for Mac

I'm runner Docker for OSX, and having trouble getting the Docker remote API to work.
My situation is this:
Docker daemon running natively on OSX (https://www.docker.com/products/docker#/mac, so not the boot2docker variant)
Jenkins running as docker image
No I want to use the Jenkins docker-build-step plugin to build a docker image, but I want it to use the docker daemon on the host machine, so in Jenkins settings, DOCKER_URL should be something like :2375. (Reason for this is I don't want to install docker on the jenkins container if I already have it on my host machine).
Is there a way to to this or is de Docker for Mac currently not supporting this? I tried fiddling with export DOCKER_OPTS or DOCKER_HOST options but still get a Connection refused on calling http://localhost:2375/images/json for example.
Basicly the question is more about enabling the Docker for OSX remote api, with use case calling it from a Jenkins docker container.
You could consider using socat. It solved my problem, which seem to be similar.
socat TCP-LISTEN:2375,reuseaddr,fork UNIX-CONNECT:/var/run/docker.sock &
This allows you to access your macOS host Docker API from a Docker container using: tcp://[host IP address]:2375
On macOS socat can be installed like this:
brew install socat
See here for a long discussion on this topic: Plugin: Docker fails to connect via unix:// on Mac OS X
If you already added an SSH public key to your remote server, then you can use this ssh credentials for your docker connection, too. You don't need to configure the remote api on the server for this approach.
When connecting to macOS Docker Desktop, you could use ssh (after you have enabled it on Mac)
docker -H ssh:user#192.168.64.1 images
or
export DOCKER_HOST=ssh:user#192.168.64.1
docker images
I had the same issue but with mysql. I needed to expose the port of my docker hosts on port 43306 to docker image mysql running on port 3306.
Solution:
Create your docker image with -p parameter.
Example:
#> docker run -p 0.0.0.0:43306:3306 --name mysql-5.7.23xx -e MYSQL_ROOT_PASSWORD=myrootdba -d mysql/mysql-server:5.7.23 --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
Now I can connect from my host docker server on port 43306 to mysql docker image.

How to call a container, running on a virtual machine, from a Windows browser?

I have Windows 7 operating system and have set up Docker. Docker starts on the virtual machine. I create some containers on Docker and test them on the command line, for example:
curl localhost:9200
Now I want to test this container from a Windows browser
http://localhost:9200
How do I call the container, which is running on a virtual machine, from a Windows browser?
Assuming you have 'published' the service to port 9200, just use the IP address of the VM instead of localhost. To get that address, you can inspect your VM setup, or use the boot2docker command:
boot2docker ip
Then, insert that address where I have the 'x's here in your browser:
http://x.x.x.x:9200
Or map published IP address from docker container running inside boot2docker like this:
boot2docker ssh -L 0.0.0.0:9200:localhost:9200
That way, you (and others that can access your computer) can acccess it on both of the following links:
http://localhost:9200
http://<host_machine_ip>:9200

Resources