title: How to connect to remote docker running on Ubuntu host
body: <p>I installed docker on an Ubuntu 16.04 following <a href="https://docs.docker.com/engine/installation/linux/ubuntu" rel="nofollow noreferrer">the official directions</a> and am successfully running the registry as a container. I want to remote connect into another container, so I try:</p>
  
  <pre><code>docker -H tcp://1.2.3.4:2375 exec -it 19f36d1bdfaf /bin/bash
  </code></pre>
  
  <p>And I get an error: </p>
  
  <blockquote>
    <p>error during connect: Post
    <a href="http://1.2.3.4:2375/v1.29/containers/19f36d1bdfaf/exec" rel="nofollow noreferrer">http://1.2.3.4:2375/v1.29/containers/19f36d1bdfaf/exec</a>: dial tcp
    1.2.3.4:2375: connectex: No connection could be made because the target machine actively refused it.</p>
  </blockquote>
  
  <p>Why am I getting this error and how do I resolve it?</p>
  
  <p>The docker.json file has contents:</p>
  
  <pre><code>{
    "hosts": [
      "tcp://0.0.0.0:2375",
      "npipe://"
    ]
  }
  </code></pre>
  
  <p>When I view the services it looks like the daemon is not listening on tcp://0.0.0.0:2375 as I would expect (this is just for testing, I'm going to secure this once I can get it actually working):
  <a href="https://i.stack.imgur.com/yhUpA.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/yhUpA.png" alt="enter image description here"></a></p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>Got it to partially work by creating a daemon.json file (a copy of docker.json), then running:</p>
  
  <pre><code>sudo dockerd
  </code></pre>
  
  <p>The problem with this is that now the client does not work: <code>docker info</code> results in an error:</p>
  
  <blockquote>
    <p>Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?</p>
  </blockquote>
  
  <p><strong>UPDATE and SOLUTION:</strong>
  Andreas' answer helped me realize the daemon was not being run properly. Looking at that screenshot earlier in this post, the docker daemon was not being launched with the right -H option. I then found <a href="https://github.com/moby/moby/issues/9889#issuecomment-109766580" rel="nofollow noreferrer">this Github issue</a> which solved the problem. So all that was needed was:</p>
  
  <ul>
  <li>Edit the $DOCKER_OPTS variable in /etc/default/docker: <code>DOCKER_OPTS="-H tcp://0.0.0.0:2375"</code> (note that this is not very secure, it's just for testing)</li>
  <li>Edit the /lib/systemd/system/docker.service file by adding a line under <code>[Service]</code> for the EnvironmentFile: <code>EnvironmentFile=-/etc/default/docker</code> then update the ExecStart line: <code>ExecStart=/usr/bin/dockerd $DOCKER_OPTS -H fd://</code></li>
  <li>Restart the service <code>sudo service docker restart</code></li>
  <li>Restart the daemon with <code>systemctl daemon-reload</code></li>
  </ul>
  
  <p>Note that I did not add a <code>daemon.json</code> file -- I left the existing <code>docker.json</code> file.</p>