简体   繁体   中英

How to enable docker containers ping each other via their host names?

I'd like to be able to ping a docker hostname from another docker container. how can i do that ? My containers are on the same docker network.

Can someone guide me where should I look or search, I'm very newbie in networking and do not know about what should i search to fix this problem.

The link option is deprecated so I suggest you to use the --network-alias option in addition to the --name flag (see the documentation here and here for more info).

For example, admiting you have a network called test, you can run these two commands (in two separate terminal)

docker run -it --rm --name debian1 --network=test --network-alias=debian1 debian:jessie /bin/bash
docker run -it --rm --name debian2 --network=test --network-alias=debian2 debian:jessie /bin/bash

Then you will be able to ping containers according to their network-alias

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM