theShadow89
theShadow89

Reputation: 1549

There is a way to ping a Docker container using its hostname, from another Docker Container?

I am looking for a solution to ping a Docker container using its hostname, from another Docker Container. I tried as follow:

starting first Docker container:

docker run --rm -ti --hostname=repohost --name=repo repo

starting second Docker container, link to first and start bash:

docker run --rm -ti --hostname=repo2host --link repo:rp repo2 /bin/bash

on bash started on repo2

ping repohost

it remain on pending without any result.

Can someone tell me if there is a solution for this?

Upvotes: 1

Views: 1695

Answers (2)

errordeveloper
errordeveloper

Reputation: 6912

One way to achieve what you need would be with WeaveDNS.

Upvotes: 0

Adrian Mouat
Adrian Mouat

Reputation: 46518

You should be able to ping using the alias you gave in the link command (the part after the :), in your case ping rp should work.

The following works for me, given a running container called furious_turing:

$ docker run -it --link furious_turing:ft debian /bin/bash root@06b18931d80b:/# ping ft PING ft (172.17.0.3): 48 data bytes 56 bytes from 172.17.0.3: icmp_seq=0 ttl=64 time=0.136 ms 56 bytes from 172.17.0.3: icmp_seq=1 ttl=64 time=0.091 ms 56 bytes from 172.17.0.3: icmp_seq=2 ttl=64 time=0.092 ms ^C--- ft ping statistics --- 3 packets transmitted, 3 packets received, 0% packet loss round-trip min/avg/max/stddev = 0.091/0.106/0.136/0.000 ms root@06b18931d80b:/#

If you need to ping on another name, you can add entries to /etc/hosts with the --add-host argument to docker run.

Upvotes: 1

Related Questions