Skip to content

How to use docker network

Posted on:November 4, 2021 at 10:10 PM

How-to

If you want to connect two containers in the same docker network.

Just do the 3 following steps:

docker network create test-network
docker run --name c1--network test-network nginx:latest
docker run --name c2 --network test-network nginx:latest

Test

Use exec to connect to the container.

docker exec -it c2 /bin/bash

(Should be provided to use curl or ping)

Curl cmd:

curl http://c2

Ping cmd:

ping c2

That is it.