For pinging the containers and creating containers on overlay network kindly refer to the below commands:
Master
sudo apt-get update
sudo apt-get install docker.io
sudo docker swarm init
sudo docker network ls
sudo docker network create --driver=overlay --attachable test
sudo docker network ls
sudo docker run -it --name ubuntu1 --network test ubuntu
Node
sudo apt-get update
sudo apt-get install docker.io
sudo docker swarm join --token SWMTKN-1-3f2a1cuc6omfjsdp5x0ybqodrvy4dvk7tz0gb3xtsr5ajxa88p-dxdlmo4hzuu4hv0kvddjpwh6u 172.31.86.175:2377
sudo docker run -it -d --name ubuntu1 --network test ubuntu
sudo docker network ls
Then on master inside the container run the below commands:
apt-get update
apt-get install iputils-ping
ping ubuntu2
Here, we are not creating replicas of the container we are creating 2 containers among master and node for pinging them above commands are helpful.
For more information, check out this Docker Tutorial.