<p>It looks like you are using <a href="/questions/tagged/docker-machine" class="post-tag" title="show questions tagged &#39;docker-machine&#39;" rel="tag">docker-machine</a> instead of <a href="/questions/tagged/docker" class="post-tag" title="show questions tagged &#39;docker&#39;" rel="tag">docker</a>.</p>

<p><a href="https://docs.docker.com/machine/get-started/#create-a-machine" rel="nofollow noreferrer">https://docs.docker.com/machine/get-started/#create-a-machine</a></p>

<blockquote>
  <p>Get the environment commands for your new VM.</p>
  
  <p>As noted in the output of the docker-machine create command, you need
  to tell Docker to talk to the new machine. You can do this with the
  docker-machine env command.</p>

<pre><code> $ docker-machine env default
 export DOCKER_TLS_VERIFY="1"
 export DOCKER_HOST="tcp://172.16.62.130:2376"
 export DOCKER_CERT_PATH="/Users/&lt;yourusername&gt;/.docker/machine/machines/default"
 export DOCKER_MACHINE_NAME="default"
 # Run this command to configure your shell:
 # eval "$(docker-machine env default)"
</code></pre>
</blockquote>

<p>Why did this solution work?</p>

<p>According to <a href="https://docs.docker.com/machine/get-started/#unset-environment-variables-in-the-current-shell" rel="nofollow noreferrer">this documentation</a> the variables have to be set over and over again.</p>

<blockquote>
  <p>Unset environment variables in the current shell</p>
  
  <p>You might want to use the current shell to connect to a different
  Docker Engine. This would be the case if, for example, you are running
  Docker for Mac concurrent with Docker Toolbox and want to talk to two
  different Docker Engines, or running swarms on Docker Cloud and want
  to switch between managing the swarm and using Docker hosts. In both
  scenarios, you have the option to switch the environment for the
  current shell to talk to different Docker engines.</p>

<pre><code>Run env|grep DOCKER to check whether DOCKER environment variables are set.

$ env | grep DOCKER
DOCKER_HOST=tcp://192.168.99.100:2376
DOCKER_MACHINE_NAME=default
DOCKER_TLS_VERIFY=1
DOCKER_CERT_PATH=/Users/victoriabialas/.docker/machine/machines/default

If it returns output (as shown in the example), you can unset the DOCKER environment variables.

Use one of two methods to unset DOCKER environment variables in the current shell.

    Run the unset command on the following DOCKER environment variables.

    unset DOCKER_TLS_VERIFY
    unset DOCKER_CERT_PATH
    unset DOCKER_MACHINE_NAME
    unset DOCKER_HOST

    Alternatively, run a shortcut command docker-machine env -u to show the command you need to run to unset all DOCKER variables:

    $ docker-machine env -u
    unset DOCKER_TLS_VERIFY
    unset DOCKER_HOST
    unset DOCKER_CERT_PATH
    unset DOCKER_MACHINE_NAME
    # Run this command to configure your shell:
    # eval $(docker-machine env -u)

    Run eval $(docker-machine env -u) to unset all DOCKER variables in the current shell.

Now, after running either of the above commands, this command should return no output.

 $ env | grep DOCKER

If you are running Docker for Mac, you can run Docker commands to talk to the Docker Engine installed with that app.

If you are running swarms on Docker Cloud, you can re-run the export command you used to connect to the swarm.

Since Docker for Windows is incompatible with Toolbox, this scenario isn’t applicable because Docker for Windows uses the Docker
</code></pre>
  
  <p>Engine and Docker Machine that come with it.</p>
</blockquote>

CC BY-SA 3.0
2017-12-30T22:10:00.477Z
Thanks for the response! Unfortunately I need to use docker-machine to manage remote hosts. The issue here does not seem to be setting the environment variables. Instead it seems to be the way docker interacts with my local DNS lookup. From what I can tell, the `backports` python package (that shipped with docker-compose 1.8 atleast) depends on the hostname `localhost` being set. This is the main source of confusion imo.
dopatraman
CC BY-SA 3.0
2017-12-30T15:48:17.530Z
2017-12-30T15:56:41.490Z
2017-12-30T15:56:41.490Z
030
<p>I <em>had</em> my docker env variables set like this:</p>

<pre><code>set -gx DOCKER_TLS_VERIFY "1";
set -gx DOCKER_HOST "tcp://xxx.xxx.xxx.xxx:2376";
set -gx DOCKER_CERT_PATH "/home/me/.docker/machine/machines/myhost";
set -gx DOCKER_MACHINE_NAME "myhost";
</code></pre>

<p>When I tried running <code>docker-compose up</code>, I got this error:</p>

<pre><code>backports.ssl_match_hostname.CertificateError: hostname 'xxx.xxx.xxx.xxx' doesn't match 'localhost'
</code></pre>

<p>But then I happened upon <a href="https://thobalose.co.za/2016/docker-compose-ssl-error/" rel="nofollow noreferrer">this blog post</a> that recommended that I set my local dns to point <code>localhost</code> to <code>xxx.xxx.xxx.xxx</code>. And it worked.</p>

<p>Why did this solution work? And more importantly, what can I do to not use it again?</p>

CC BY-SA 3.0
2017-12-30T10:44:07.133Z
Why do you not use the default docker variables? What OS do you use?
030
CC BY-SA 3.0
2017-12-30T22:10:17.393Z
I am. those are the default docker env variables.
dopatraman
<docker-machine>
Had to point localhost to remote ip for docker-compose to work. why?
dopatraman
# Had to point localhost to remote ip for docker-compose to work. why?

(Asked by: username_0 on 2017-12-30)

I had my docker env variables set like this:
set -gx DOCKER_TLS_VERIFY "1";
set -gx DOCKER_HOST "tcp://xxx.xxx.xxx.xxx:2376";
set -gx DOCKER_CERT_PATH "/home/me/.docker/machine/machines/myhost";
set -gx DOCKER_MACHINE_NAME "myhost";

When I tried running docker-compose up, I got this error:
backports.ssl_match_hostname.CertificateError: hostname 'xxx.xxx.xxx.xxx' doesn't match 'localhost'

But then I happened upon this blog post that recommended that I set my local dns to point localhost to xxx.xxx.xxx.xxx. And it worked.
Why did this solution work? And more importantly, what can I do to not use it again?

**Tags:** docker-machine

> **Comments:**
> **username_1**: Why do you not use the default docker variables? What OS do you use?  
> **username_0**: I am. those are the default docker env variables.  

---

## 1 answers

### Answer by username_1 on 2017-12-30. Score: 1

It looks like you are using docker-machine instead of docker.
https://docs.docker.com/machine/get-started/#create-a-machine

Get the environment commands for your new VM.
As noted in the output of the docker-machine create command, you need
  to tell Docker to talk to the new machine. You can do this with the
  docker-machine env command.
 $ docker-machine env default
 export DOCKER_TLS_VERIFY="1"
 export DOCKER_HOST="tcp://172.16.62.130:2376"
 export DOCKER_CERT_PATH="/Users//.docker/machine/machines/default"
 export DOCKER_MACHINE_NAME="default"
 # Run this command to configure your shell:
 # eval "$(docker-machine env default)"


Why did this solution work?
According to this documentation the variables have to be set over and over again.

Unset environment variables in the current shell
You might want to use the current shell to connect to a different
  Docker Engine. This would be the case if, for example, you are running
  Docker for Mac concurrent with Docker Toolbox and want to talk to two
  different Docker Engines, or running swarms on Docker Cloud and want
  to switch between managing the swarm and using Docker hosts. In both
  scenarios, you have the option to switch the environment for the
  current shell to talk to different Docker engines.
Run env|grep DOCKER to check whether DOCKER environment variables are set.

$ env | grep DOCKER
DOCKER_HOST=tcp://192.168.99.100:2376
DOCKER_MACHINE_NAME=default
DOCKER_TLS_VERIFY=1
DOCKER_CERT_PATH=/Users/victoriabialas/.docker/machine/machines/default

If it returns output (as shown in the example), you can unset the DOCKER environment variables.

Use one of two methods to unset DOCKER environment variables in the current shell.

    Run the unset command on the following DOCKER environment variables.

    unset DOCKER_TLS_VERIFY
    unset DOCKER_CERT_PATH
    unset DOCKER_MACHINE_NAME
    unset DOCKER_HOST

    Alternatively, run a shortcut command docker-machine env -u to show the command you need to run to unset all DOCKER variables:

    $ docker-machine env -u
    unset DOCKER_TLS_VERIFY
    unset DOCKER_HOST
    unset DOCKER_CERT_PATH
    unset DOCKER_MACHINE_NAME
    # Run this command to configure your shell:
    # eval $(docker-machine env -u)

    Run eval $(docker-machine env -u) to unset all DOCKER variables in the current shell.

Now, after running either of the above commands, this command should return no output.

 $ env | grep DOCKER

If you are running Docker for Mac, you can run Docker commands to talk to the Docker Engine installed with that app.

If you are running swarms on Docker Cloud, you can re-run the export command you used to connect to the swarm.

Since Docker for Windows is incompatible with Toolbox, this scenario isn’t applicable because Docker for Windows uses the Docker

Engine and Docker Machine that come with it.

> **Comments:**
> **username_0**: Thanks for the response! Unfortunately I need to use docker-machine to manage remote hosts. The issue here does not seem to be setting the environment variables. Instead it seems to be the way docker interacts with my local DNS lookup. From what I can tell, the `backports` python package (that shipped with docker-compose 1.8 atleast) depends on the hostname `localhost` being set. This is the main source of confusion imo.  

---

