What does the DOCKER_HOST variable do?

后端 未结 3 648
鱼传尺愫
鱼传尺愫 2021-01-30 02:14

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 DOCKE         


        
3条回答
  •  情话喂你
    2021-01-30 03:03

    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.

提交回复
热议问题