I have a simple docker-compose set up as follows.
version: \"3\"
services:
main:
image: python:3.5.2
entrypoint: /usr/bin/yes
network_mode: bridge
Another solution I tried and worked was explicitly linking the containing you want to ping with host name. For example, I have a postgres
container, and a server
wants to connect to it.
Run the server
with the following
docker run --name server --link postgres someserver:latest
In the server container environment, you can then ping with (given postgres
is on the same bridge/network and is running)
ping postgres
Since --link
has been deprecated, it is recommended to use network bridge.
docker network create YOURNETWORK
docker run --name postgres --network='YOURNETWORK' postgres:latest
docker run --name server --network='YOURNETWORK' server:latest
then the two containers can ping each other by name.