title: Docker for mac - can't curl my container
body: <p>Running docker for Mac 17.06.0 I have created a docker file that creates an image of Apache server. Notice it exposes port 80.</p>
  
  <pre><code>FROM ubuntu:16.04
  RUN apt-get update
  RUN apt-get install -y apache2
  ADD index.html /var/www/html/
  CMD /usr/sbin/apache2ctl -D FOREGROUND
  EXPOSE 80 
  </code></pre>
  
  <p>In the same folder of the Dockerfile I have created a simple index.httml file.<br>
  Then I built and ran it using</p>
  
  <pre><code>docker build -t webserver .
  docker run -d webserver 
  </code></pre>
  
  <p>I took the IP address of the running container using </p>
  
  <pre><code>docker inspect [container_name] | grep -i IPAddress
  </code></pre>
  
  <p>and when I curl </p>
  
  <pre><code>curl 172.17.0.2
  </code></pre>
  
  <p>I get no answer.</p>
  
  <p>I do get an answer when running -p 80:80 and using localhost in the curl command.  </p>
  
  <pre><code> curl localhost
  </code></pre>
  
  <p>But I want to understand why can't I curl the container IP. </p>
  
  <p>Questions:  </p>
  
  <ol>
  <li>How can I get an answer for my curl?</li>
  <li>I understand I can't ping my container when using docker for Mac (<a href="https://docs.docker.com/docker-for-mac/networking/#i-cannot-ping-my-containers" rel="noreferrer">link</a>).<br>
  Can I telnet it just to verify that the port is exposed?</li>
  <li>Can I SSH it?</li>
  </ol>