Docker for mac - can't roll my container

Running Docker for Mac 17.06.0 I created a docker file that creates an image of the Apache server. Note that it provides 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 Dockerfile folder, I 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 of a running container using

docker inspect [container_name] | grep -i IPAddress

      

and when I curl

curl 172.17.0.2

      

I am not getting an answer.

I am getting a response when running -p 80:80 and using localhost in the curl command.

 curl localhost

      

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

Questions:

  • How can I get an answer for my curl?
  • I understand that I cannot ping my container when using docker for Mac ( link ).
    Can I use telnet to check that the port is open?
  • Can I use SSH?
+3


source to share


2 answers


In Docker for Mac, the Docker engine runs inside a small virtual machine using Hyper-V. As a consequence, the ip 172.17.0.2

is only valid inside this virtual machine, not your host system. See https://docs.docker.com/docker-for-mac/docker-toolbox/#the-docker-for-mac-environment for more details and comparison with other VM concepts like Docker Machine.



+2


source


When you start a Docker container, you need to bind a local port to the container like this:

docker run -d -p 80:80 webserver

      



where the first 80

is the port on localhost and the second is the port on the exponent. Just having a port open at dockerfile

is not enough to access it from localhost.

0


source







All Articles