Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker for mac - can't curl my container

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?
like image 604
Bick Avatar asked Jul 29 '17 14:07

Bick


1 Answers

On Docker for Mac the Docker engine is running inside a small VM using Hyper-V. As consequence, the ip 172.17.0.2 is valid only inside that VM and not on your host system. See https://docs.docker.com/docker-for-mac/docker-toolbox/#the-docker-for-mac-environment for more details and comparison to other VM concepts like Docker Machine.

like image 104
gesellix Avatar answered Oct 05 '22 23:10

gesellix