Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No /var/run/docker.sock on OS X

Tags:

docker

macos

I'm trying to use REST calls to access Docker information. I tried this example I pulled off a web site:

echo -e "GET /images/json HTTP/1.0\r\n" | nc -U /var/run/docker.sock

I got no errors but nothing happened. I have docker images on my system (I can do 'docker images' and see a list). I have no issues running command-line docker tools.

Looking at the file system, there is no /var/run/docker.sock on my system.

I'm using an out-of-the-box boot2docker installation on OS X. Docker info output is here:

bash-3.2$ docker info
Containers: 6
Images: 174
Storage Driver: aufs
 Root Dir: /mnt/sda1/var/lib/docker/aufs
 Dirs: 186
Execution Driver: native-0.2
Kernel Version: 3.16.7-tinycore64
Operating System: Boot2Docker 1.3.2 (TCL 5.4); master : 495c19a - Mon Nov 24 20:40:58 UTC 2014
Debug mode (server): true
Debug mode (client): false
Fds: 11
Goroutines: 13
EventsListeners: 0
Init Path: /usr/local/bin/docker

What am I missing?

like image 350
Greg Avatar asked May 22 '15 14:05

Greg


People also ask

What is var run Docker sock?

sock is basically the Unix socket the Docker daemon listens on by default. It is also a tool used to communicate with the Docker daemon from within a container. Sometimes, containers need to bind mount the /var/run/docker. sock file.

How do I run Docker daemon on Mac?

On MacOS go to the whale in the taskbar > Preferences > Daemon > Advanced. You can also start the Docker daemon manually and configure it using flags. This can be useful for troubleshooting problems. Many specific configuration options are discussed throughout the Docker documentation.

How do I run Docker natively on a Mac?

Currently, to use Docker on Mac and Windows requires the use of Docker Toolbox. You have to download it, install a bunch of tools and dependencies for it to work. And since Docker uses Linux-specific tools you can't run it natively. Instead, you have to use docker-machine and attach to a VirtualBox VM on your system.

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.


1 Answers

Docker runs on 64-bit linux kernels only. If you're using boot2docker, you're actually talking to an install of Docker inside a virtualbox VM. The Docker client (on your Mac) is actually making REST calls over TLS to the Docker daemon inside the VM.

As your Docker daemon is already set up to do TLS, you don't need to use the nc trick to talk to the socket, we can just use curl directly. Unfortunately, the version of curl installed on Macs doesn't support the certificate type used in boot2docker, so we have to create a new certificate first:

$ cd ~/.boot2docker/certs/boot2docker-vm/
$ openssl pkcs12 -export -inkey key.pem \
         -in cert.pem -name b2d-client-side \
         -out b2d-client-side.p12 \
         -password pass:tcuser

This should create the file b2d-client-side.p12. (I took these instructions from https://github.com/boot2docker/boot2docker/issues/573). Now we can use curl:

$ curl \
     --cacert ~/.boot2docker/certs/boot2docker-vm/ca.pem \
     --cert ~/.boot2docker/certs/boot2docker-vm/b2d-client-side.p12:tcuser  \
     https://$(boot2docker ip):2376/images/json
[{"Created":1432076009,"Id":"b96d1548a24e2a089512da28da79ce70825f6d7f"....
like image 155
Adrian Mouat Avatar answered Oct 21 '22 12:10

Adrian Mouat