Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ping Docker Container from another machine in the network

I have created a docker container and tried pinging www.google.com within the bash of the container and it works. Also I tried pinging the container from the host - it works perfectly fine.

But when I try to ping the container from a external system in the network, it gives me a request timed out exception.

I am planning to install a tomcat webserver on a container and allow other containers to access the application deployed in the server. Would appreciate some help!

like image 354
cucucool Avatar asked Jun 10 '14 19:06

cucucool


1 Answers

You cannot ping a Docker container from an external host by default (to do so, you would have to ensure that the Docker network bridge -docker0- has an IP Address, and you would have to configure routes on your other hosts to use you Docker host as a gateway for the bridge address range).

By default, any service running inside a Docker container is not "Published" (Docker terminology) and cannot be reached from outside. You have to explicitly define/allow the services you want to be published when you run your container.

For example, to publish your container's Tomcat app (supposing it is configured to listen on port 8080) to port 80 on the host, you would run your container using the -p option :

    docker run -d -p 80:8080 my-tomcat-image:tag 

But if you only want to access Tomcat from other containers on the same host, you don't need to configure anything.

like image 70
mbarthelemy Avatar answered Nov 10 '22 04:11

mbarthelemy