Table of Contents


Description

1. Create the bridge

docker network create test-radiusdesk
#This was the result
f67e11184a174cf7fb82ba85734dd6d895f0690738cb07246fd7ee13b0024761
docker network ls
#This was the result
NETWORK ID     NAME                DRIVER    SCOPE
395e31953e3c   bridge              bridge    local
0d8b3aa905bf   host                host      local
17e0830302a8   none                null      local
f67e11184a17   test-radiusdesk     bridge    local
17: br-f67e11184a17: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default 
    link/ether fe:67:4b:58:62:66 brd ff:ff:ff:ff:ff:ff
    inet 172.20.0.1/16 brd 172.20.255.255 scope global br-f67e11184a17
       valid_lft forever preferred_lft forever

2.Run two nginx containers on that bridge

# Container 1 -> host port 8000
docker run -d --name nginx-8000 --network test-radiusdesk -p 8000:80 nginx
 
# Container 2 -> host port 8001
docker run -d --name nginx-8001 --network test-radiusdesk -p 8001:80 nginx

3. Test from your laptop

curl http://localhost:8000
curl http://localhost:8001

4. Prove they can talk to each other by name (the bridge magic)

docker exec -it nginx-8000 ping nginx-8001
docker exec -it nginx-8000 curl http://nginx-8001

Useful cleanup / debug

docker ps                           # see running
docker network inspect test-radiusdesk  # see which containers + their IPs
docker logs nginx-8000
docker stop nginx-8000 nginx-8001 && docker rm nginx-8000 nginx-8001
docker network rm test-radiusdesk

Same thing with docker-compose (cleaner)

services:
  nginx-8000:
    image: nginx
    ports:
      - "8000:80"
    networks:
      - test-radiusdesk

  nginx-8001:
    image: nginx
    ports:
      - "8001:80"
    networks:
      - test-radiusdesk

networks:
  test-radiusdesk:
    driver: bridge
docker compose up -d
docker compose down