title: Docker - Failed to connect to localhost port 4000: Connection refused
body: <p>Hi I'm very new to Docker, I'm trying to get familiar with Docker by following the tutorial on official site. Now I get stuck at part 2 of the tutorial (where you can check up the link here => <a href="https://docs.docker.com/get-started/part2/#run-the-app" rel="noreferrer">https://docs.docker.com/get-started/part2/#run-the-app</a>)</p>
  
  <p>I have sample application code, Dockerfile, and requirements.txt exactly same as the offical tutorial</p>
  
  <pre><code>$ ls
  app.py  Dockerfile  requriements.txt
  </code></pre>
  
  <p>My Dockerfile looks like this</p>
  
  <pre><code>FROM python:2.7-slim
  WORKDIR /app
  ADD . /app
  RUN pip install -r requriements.txt
  EXPOSE 80
  ENV NAME World
  CMD ["python", "app.py"]
  </code></pre>
  
  <p>All 3 files have file content/code exactly same as the tutorial also. I was able to build image registry with this command</p>
  
  <pre><code>$ docker build -t friendlyhello .
  </code></pre>
  
  <p>Everything looks great. Now I had sample project image registry.</p>
  
  <pre><code>$ docker images
  REPOSITORY          TAG                 IMAGE ID            CREATED
  friendlyhello       latest              82b8a0b52e91        39 minutes ago
  python              2.7-slim            1c7128a655f6        5 days ago
  hello-world         latest              48b5124b2768        4 months ago
  </code></pre>
  
  <p>I then ran the app according to the official tutorial with this command</p>
  
  <pre><code>$ docker run -d -p 4000:80 friendlyhello
  c1893f7eea9f1b708f639653b8eba20733d8a45d3812b442bc295b43c6c7dd5c
  </code></pre>
  
  <p><strong>Edit</strong>: This is my container after ran above command</p>
  
  <pre><code>$ docker ps -a
  CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS
  c1893f7eea9f        friendlyhello       "python app.py"     15 minutes ago      Up 16 minutes
  </code></pre>
  
  <p>And the official tutorial guides readers to have a look at <code>http://localhost:4000</code> as they have already mapped machine port <code>4000</code> to container port <code>80</code></p>
  
  <p>Unfortunately, I couldn't get any response from that URL.</p>
  
  <pre><code>$ curl http://localhost:4000
  curl: (7) Failed to connect to localhost port 4000: Connection refused
  </code></pre>
  
  <p>I'm totally newbie and I have no idea what to do....How can I get it to work ?
  Thanks in advance for any response.</p>
  
  <p><strong>Edit</strong>: I did as @johnharris85 suggested. Below is the output</p>
  
  <pre><code>$ curl http://$(echo docker-machine ip default):4000
  curl: (6) Couldn't resolve host 'docker-machine'
  curl: (6) Couldn't resolve host 'ip'
  curl: (6) Couldn't resolve host 'default'
  </code></pre>
  
  <p>It seems like it doesn't work either.</p>
  
  <p><strong>Edit</strong>: @johnharris85 corrected his suggestion and @user8023051 clarify how this command come from and what is going on under the hood. It is working now :) Thanks</p>
  
  <pre><code>$ curl http://$(docker-machine ip default):4000
  &lt;h3&gt;Hello World!&lt;/h3&gt;&lt;b&gt;Hostname:&lt;/b&gt; c1893f7eea9f&lt;br/&gt;&lt;b&gt;Visits:&lt;/b&gt; &lt;i&gt;cannot connect to Redis, counter disabled&lt;/i&gt;
  </code></pre>