Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker error dial unix /var/run/docker.sock: no such file or directory

I use to have boot2docker installed but recently installed the Docker ToolBox app for the Mac (running 10.11). When I open up iTerm and type docker ps I get the following message.

Get http:///var/run/docker.sock/v1.20/containers/json: dial unix /var/run/docker.sock: no such file or directory.
* Are you trying to connect to a TLS-enabled daemon without TLS?
* Is your docker daemon up and running?

I use to use boot2docker so I assumed the ToolBox is now needed. I started the app Docker quick start terminal which works only inside their terminal. However, I want to use docker in my own terminal etc.

Why do I get this error? How to fix?

like image 311
Prometheus Avatar asked Oct 16 '15 11:10

Prometheus


2 Answers

The docker toolbox now uses docker-machine to create docker hosts. The error you're seeing is likely because you did not set an active machine.

First make sure you have a docker host running with docker-machine ls. Then set an active machine with

eval $(docker-machine env default)

Where default is the name of the machine from the ls output.

I created a quick and dirty helper you can use to show your currently active machine in your prompt if you like: https://gist.github.com/aburnett/1165239cd2673a43579c

like image 159
Adam B Avatar answered Sep 30 '22 13:09

Adam B


Edit: You will probably want to use Adam B's answer as docker-machine is the standard way of handling "remote" docker engines now. Thanks for pointing this out Adam B.

E.g. eval $(docker-machine env default)

Original answer:

On OS X the Docker Engine runs inside a virtual machine (most commonly Virtualbox). To enable communication with this Docker Engine the Docker quick start terminal sets a couple of environment variables that tells the docker binary on your OS X installation to use the Virtualbox-hosted Docker Engine.

$ export DOCKER_TLS_VERIFY="1"
$ export DOCKER_HOST="tcp://ip.of.virtual.machine:2376"
$ export DOCKER_CERT_PATH="/path/to/certificates/"

I'm not on my Mac now and don't remember the exact values used. The same set of environment variables will be set when opening the Docker CLI tools from the Kitematic gui.

If you can find out the commands and values being used you can add these three commands to the bottom of your .bashrc, .zshrc, or equivalent terminal configuration file and restarting or sourcing (source ~/.bashrc) the configuration file.

This will cause the docker binary to use the boot2docker virtualbox docker engine by default even when you don't open your terminal through the Docker Toolbox tools (Kitematic etc).

like image 35
Snorre Avatar answered Sep 30 '22 14:09

Snorre