What does the DOCKER_HOST variable do? What does the DOCKER_HOST variable do? docker docker

What does the DOCKER_HOST variable do?


Ok, I think I got it.

The client is the docker command installed into OS X.

The host is the Boot2Docker VM.

The daemon is a background service running inside Boot2Docker.

This variable tells the client how to connect to the daemon.

When starting Boot2Docker, the terminal window that pops up already has DOCKER_HOST set, so that's why docker commands work. However, to run Docker commands in other terminal windows, you need to set this variable in those windows.

Failing to set it gives a message like this:

$ docker run hello-world2014/08/11 11:41:42 Post http:///var/run/docker.sock/v1.13/containers/create: dial unix /var/run/docker.sock: no such file or directory

One way to fix that would be to simply do this:

$ export DOCKER_HOST=tcp://192.168.59.103:2375

But, as pointed out by others, it's better to do this:

$ $(boot2docker shellinit)$ docker run hello-worldHello from Docker. [...]

To spell out this possibly non-intuitive Bash command, running boot2docker shellinit returns a set of Bash commands that set environment variables:

export DOCKER_HOST=tcp://192.168.59.103:2376export DOCKER_CERT_PATH=/Users/ddavison/.boot2docker/certs/boot2docker-vmexport DOCKER_TLS_VERIFY=1

Hence running $(boot2docker shellinit) generates those commands, and then runs them.


Upon investigation, it's also worth noting that when you want to start using docker in a new terminal window, the correct command is:

$(boot2docker shellinit)

I had tested these commands:

>>  docker infoGet http:///var/run/docker.sock/v1.15/info: dial unix /var/run/docker.sock: no such file or directory>>  boot2docker shellinitWriting /Users/ddavison/.boot2docker/certs/boot2docker-vm/ca.pemWriting /Users/ddavison/.boot2docker/certs/boot2docker-vm/cert.pemWriting /Users/ddavison/.boot2docker/certs/boot2docker-vm/key.pem    export DOCKER_HOST=tcp://192.168.59.103:2376    export DOCKER_CERT_PATH=/Users/ddavison/.boot2docker/certs/boot2docker-vm    export DOCKER_TLS_VERIFY=1>> docker infoGet http:///var/run/docker.sock/v1.15/info: dial unix /var/run/docker.sock: no such file or directory

Notice that docker info returned that same error. however.. when using $(boot2docker shellinit)...

>>  $(boot2docker init)Writing /Users/ddavison/.boot2docker/certs/boot2docker-vm/ca.pemWriting /Users/ddavison/.boot2docker/certs/boot2docker-vm/cert.pemWriting /Users/ddavison/.boot2docker/certs/boot2docker-vm/key.pem>>  docker infoContainers: 3...


It points to the docker host! I followed these steps:

$ boot2docker startWaiting for VM and Docker daemon to start.................................Started.To connect the Docker client to the Docker daemon, please set:    export DOCKER_HOST=tcp://192.168.59.103:2375$ export DOCKER_HOST=tcp://192.168.59.103:2375$ docker run ubuntu:14.04 /bin/echo 'Hello world'Unable to find image 'ubuntu:14.04' locallyPulling repository ubuntu9cbaf023786c: Download complete 511136ea3c5a: Download complete 97fd97495e49: Download complete 2dcbbf65536c: Download complete 6a459d727ebb: Download complete 8f321fc43180: Download complete 03db2b23cf03: Download complete Hello world

See:
http://docs.docker.com/userguide/dockerizing/