Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the DOCKER_HOST variable do?

I'm new to Docker, using Boot2Docker on OSX. After booting it, this message is given:

To connect the Docker client to the Docker daemon, please set export DOCKER_HOST=tcp://192.168.59.103:2375 

Yet even without it, basic Docker commands (eg, docker run hello-world) work fine.

The install instructions aren't very informative:

Note: If you see a message in the terminal that looks something like this: To connect the Docker client to the Docker daemon, please set:  export  DOCKER_HOST=tcp://192.168.59.103:2375 you can safely set the evironment variable as instructed. 

Knowing that it's "safe" doesn't say why it's useful.

What I'm not clear on:

  1. What is the docker "client"?
  2. What is the docker "daemon"?
  3. What is the docker "host"? (The Boot2Docker VM itself?)
like image 270
Steve Bennett Avatar asked Aug 11 '14 01:08

Steve Bennett


People also ask

What is the purpose of Docker_host?

The Docker CLI uses the DOCKER_HOST environment variable to determine the host to connect to. The local daemon's Unix socket will be used when the variable isn't set. This will start a new container from the httpd:latest image using the Docker engine at 192.168.

What is the default Docker_host?

docker_host. string. Default: "unix://var/run/docker.sock" The URL or Unix socket path used to connect to the Docker API.

What are environment variables in Dockerfile?

Overview. Environment variables are a convenient way to externalize application configuration. Therefore they are also useful for building Docker containers. However, passing and using them in the Dockerfile is not as easy as it might be.

How do I access docker environment variables?

Fetch Using docker exec Command Here, we are executing the /usr/bin/env utility inside the Docker container. Using this utility, you can view all the environment variables set inside Docker containers.


2 Answers

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-world 2014/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-world Hello 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:2376 export DOCKER_CERT_PATH=/Users/ddavison/.boot2docker/certs/boot2docker-vm export DOCKER_TLS_VERIFY=1 

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

like image 94
Steve Bennett Avatar answered Sep 28 '22 08:09

Steve Bennett


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 info Get http:///var/run/docker.sock/v1.15/info: dial unix /var/run/docker.sock: no such file or directory >>  boot2docker shellinit Writing /Users/ddavison/.boot2docker/certs/boot2docker-vm/ca.pem Writing /Users/ddavison/.boot2docker/certs/boot2docker-vm/cert.pem Writing /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 info Get 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.pem Writing /Users/ddavison/.boot2docker/certs/boot2docker-vm/cert.pem Writing /Users/ddavison/.boot2docker/certs/boot2docker-vm/key.pem >>  docker info Containers: 3 ... 
like image 21
ddavison Avatar answered Sep 28 '22 09:09

ddavison