kasterma
kasterma

Reputation: 4469

Docker seems to ignore DOCKER_HOST and other vars set from `eval $(docker-machine env)`

I am on OS X, with docker installed through brew. Trying to use the combination of docker-machine and docker. Docker seems to ignore my environment settings. How can I fix this?

   $ docker-machine env default2
   export DOCKER_TLS_VERIFY="1"
   export DOCKER_HOST="tcp://192.168.99.100:2376"
   export DOCKER_CERT_PATH="/Users/kasterma/.docker/machine/machines/default2"
   export DOCKER_MACHINE_NAME="default2"
   # Run this command to configure your shell:
   # eval $(docker-machine env default2)

   $ eval $(docker-machine env default2)

My understanding is that now everything is set up in the shell as it should be to use docker. However:

   $ docker ps
   Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

If I specify everything on the command line it works

   $ docker -H tcp://192.168.99.100:2376 --tls --tlscacert /Users/kasterma/.docker/machine/machines/default2/ca.pem --tlscert /Users/kasterma/.docker/machine/machines/default2/cert.pem --tlskey /Users/kasterma/.docker/machine/machines/default2/key.pem ps
   CONTAINER ID        NAMES               IMAGE               STATUS

Together they seem to indicate the environment variables are ignored. Note that they are set correctly (the more indented parts of the output here are, I believe, from the command line completion).

   $ set | grep DOCK
   DOCKER_CERT_PATH=/Users/kasterma/.docker/machine/machines/default2
   DOCKER_HOST=tcp://192.168.99.100:2376
   DOCKER_MACHINE_NAME=default2
   DOCKER_TLS_VERIFY=1
               if [ "${DOCKER_COMPLETION_SHOW_CONTAINER_IDS}" = yes ]; then
       case "$DOCKER_COMPLETION_SHOW_IMAGE_IDS" in
       if [ "${DOCKER_COMPLETION_SHOW_TAGS:-yes}" = "yes" ]; then
       case "$DOCKER_COMPLETION_SHOW_IMAGE_IDS" in
       if test ${DOCKER_MACHINE_NAME}; then
           if test ${DOCKER_MACHINE_PS1_SHOWSTATUS:-false} = true; then
               status=$(docker-machine status ${DOCKER_MACHINE_NAME});
           printf -- "${format}" "${DOCKER_MACHINE_NAME}${status}";
                   echo "Active machine: ${DOCKER_MACHINE_NAME}"
               if [ "${DOCKER_COMPLETION_SHOW_NETWORK_IDS}" = yes ]; then
       [ "${DOCKER_COMPLETION_SHOW_NODE_IDS}" = yes ] && fields='$1,$2';
       if [ "$DOCKER_COMPLETION_SHOW_PLUGIN_IDS" = yes ]; then
               if [ "$DOCKER_COMPLETION_SHOW_SECRET_IDS" = yes ]; then
       [ "${DOCKER_COMPLETION_SHOW_SERVICE_IDS}" = yes ] && fields='$1,$2';
       [ -z "$DOCKER_HIDE_LEGACY_COMMANDS" ] && commands+=(${legacy_commands[*]});
       if  ${DOCKER_MACHINE_WRAPPED} = true ; then

Here is my docker version information

$ docker -H tcp://192.168.99.100:2376 --tls --tlscacert /Users/kasterma/.docker/machine/machines/default2/ca.pem --tlscert /Users/kasterma/.docker/machine/machines/default2/cert.pem --tlskey /Users/kasterma/.docker/machine/machines/default2/key.pem version
Client:
 Version:      17.05.0-ce
 API version:  1.29
 Go version:   go1.8.1
 Git commit:   89658be
 Built:
 OS/Arch:      darwin/amd64

Server:
 Version:      17.05.0-ce
 API version:  1.29 (minimum version 1.12)
 Go version:   go1.7.5
 Git commit:   89658be
 Built:        Thu May  4 21:43:09 2017
 OS/Arch:      linux/amd64
 Experimental: false

And showing the docker binaries linking to the brew versions (with some stuff left over from having run the OS X version of docker before).

$ ls -l dock*
lrwxr-xr-x 1 kasterma admin       35 Jun  5 12:14 docker -> ../Cellar/docker/17.05.0/bin/docker
lrwxr-xr-x 1 kasterma admin       50 Jun  5 12:15 docker-compose -> ../Cellar/docker-compose/1.13.0/bin/docker-compose
-rwxr-xr-x 1 kasterma admin  4938393 Dec  4  2015 docker-compose.backup
lrwxr-xr-x 1 kasterma staff       91 Jun  5 11:54 docker-credential-osxkeychain -> '/Users/kasterma/Library/Group Containers/group.com.docker/bin/docker-credential-osxkeychain'
lrwxr-xr-x 1 kasterma admin       50 Jun  5 12:12 docker-machine -> ../Cellar/docker-machine/0.11.0/bin/docker-machine
-rwxr-xr-x 1 kasterma admin  7417984 Dec  1  2015 docker-machine-driver-amazonec2
-rwxr-xr-x 1 kasterma admin  8112752 Dec  1  2015 docker-machine-driver-azure
-rwxr-xr-x 1 kasterma admin  7355040 Dec  1  2015 docker-machine-driver-digitalocean
-rwxr-xr-x 1 kasterma admin  7343472 Dec  1  2015 docker-machine-driver-exoscale
-rwxr-xr-x 1 kasterma admin  7471952 Dec  1  2015 docker-machine-driver-generic
-rwxr-xr-x 1 kasterma admin 10575760 Dec  1  2015 docker-machine-driver-google
-rwxr-xr-x 1 kasterma admin  7362496 Dec  1  2015 docker-machine-driver-hyperv
-rwxr-xr-x 1 kasterma admin  6830912 Dec  1  2015 docker-machine-driver-none
-rwxr-xr-x 1 kasterma admin  7709792 Dec  1  2015 docker-machine-driver-openstack
-rwxr-xr-x 1 kasterma admin  7778992 Dec  1  2015 docker-machine-driver-rackspace
-rwxr-xr-x 1 kasterma admin  7328400 Dec  1  2015 docker-machine-driver-softlayer
-rwxr-xr-x 1 kasterma admin  8046416 Dec  1  2015 docker-machine-driver-virtualbox
-rwxr-xr-x 1 kasterma admin  7907168 Dec  1  2015 docker-machine-driver-vmwarefusion
-rwxr-xr-x 1 kasterma admin  7545600 Dec  1  2015 docker-machine-driver-vmwarevcloudair
-rwxr-xr-x 1 kasterma admin  7449392 Dec  1  2015 docker-machine-driver-vmwarevsphere
-rwxr-xr-x 1 kasterma admin  9039648 Dec  1  2015 docker-machine.backup
-rwxr-xr-x 1 kasterma admin  9231840 Dec  4  2015 docker.backup

Upvotes: 1

Views: 1635

Answers (1)

BMitch
BMitch

Reputation: 264851

From the comments, your docker command was aliased to sudo docker. The sudo command will not pass through the environment variables defined by docker-machine so it will default back to the /var/lib/docker.sock.

As for which vs type, which will point to a binary in the $PATH to let you know where something is located. type will let you know how the shell is running that command including shell built-ins, any aliases, or function definitions.

To solve this, remove the alias from your bash scripts and launch a new shell. In an existing shell that has the alias, you can run unalias docker or /usr/local/bin/docker (with the full path). In environments where you used sudo, consider adding the user to the docker group with:

sudo usermod -aG docker `whoami` && newgrp docker

That will give you group level access to the docker socket so you don't need to run sudo for the docker commands.

Upvotes: 5

Related Questions