Ping Docker Container from another machine in the network
Asked Answered
S

3

8

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!

Salmonella answered 10/6, 2014 at 19:4 Comment(0)
B
8

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.

Begonia answered 10/6, 2014 at 19:56 Comment(1)
Tried to add a route from host1 to the docker container network inside of host2. Is this possible? I tried to add the static route on host1 with the 172.17.x.x(docker network on host2) and put the gateway as host2. I dont get any packets to host2. Is there something I need to look into? 172.17.0.0 172.31.69.211 255.255.0.0 UG 0 0 0 eth0 is the route on host1 pointing to host2 ip address.Cowling
P
0

There is a way to accomplish this without the need to configure routes on your other hosts, at least using Podman, not sure about Docker. You can use CNI plugin ipvlan for this:

{
  "cniVersion": "0.4.0",
  "name": "podman",
  "plugins": [
    {
      "type": "ipvlan",
      "master": "baremetal",
      "bridge": "cni-podman0",
      "isGateway": false,
      "isDefaultGateway": false,
      "ipMasq": false,
      "hairpinMode": false,
      "promiscMode": true,
      "ipam": {
        "type": "host-local",
        "ranges": [
          [
            {
              "subnet": "192.168.216.0/21"
            }
          ]
        ]
      }
    }
  ]
}

Then you just create the containers with IPs in the subnet (I am assuming 192.168.216.0/21 is the subnet of the external systems in your network):

podman run --ip 192.168.216.201 -d quay.io/frrouting/frr

This containers will be reachable from your external systems (not by the host running the container though).

Pushup answered 22/1, 2022 at 13:57 Comment(0)
R
0

I installed docker desktop in windows 10. I faced similar challenge to ping the container from windows 10. Since the docker host cannot reach the linux containers(Known limitations, use cases, and workarounds), here is a way to reach out the container ip. We can ping via vEthernet WSL ip to Docker Gateway to Container ip.

Solution:

  1. type "ipconfig /all" in host command prompt.
  2. find the ip of "Ethernet adapter vEthernet (WSL)"

vEthernet (WSL) ip

Containers running:

Ping thru vEthernet (WSL) ip

Similar to the above, other containers are also pinging from windows 10.

Hope this helps for windows users.

Rachael answered 10/2, 2022 at 15:19 Comment(2)
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.Monosaccharide
I edited the content with little bit clarity.Rachael

© 2022 - 2024 — McMap. All rights reserved.