Docker for mac - can't curl my container

Viewed 4796

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.

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 

In the same folder of the Dockerfile I have created a simple index.httml file.
Then I built and ran it using

docker build -t webserver .
docker run -d webserver 

I took the IP address of the running container using

docker inspect [container_name] | grep -i IPAddress

and when I curl

curl 172.17.0.2

I get no answer.

I do get an answer when running -p 80:80 and using localhost in the curl command.

 curl localhost

But I want to understand why can't I curl the container IP.

Questions:

  1. How can I get an answer for my curl?
  2. I understand I can't ping my container when using docker for Mac (link).
    Can I telnet it just to verify that the port is exposed?
  3. Can I SSH it?
2 Answers
Related