Создать общую сеть, запустить контейнеры в этой сети:
docker network create commonnet
docker run --rm --name nginx1 -d --network commonnet nginx
docker run --rm --name nginx2 -d --network commonnet nginx
далее
docker exec -it nginx1 bash
apt update
apt install iputils-ping
ping nginx2
PING nginx2 (10.31.3.3) 56(84) bytes of data.
64 bytes from nginx2.testnet (10.31.3.3): icmp_seq=1 ttl=64 time=0.054 ms
64 bytes from nginx2.testnet (10.31.3.3): icmp_seq=2 ttl=64 time=0.043 ms
...
или
curl nginx2
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
html { color-scheme: light dark; }
body { width: 35em; margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif; }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>
PS
ну либо docker-compose как уже посоветовали...