This is an old revision of the document!
Description
- We start out with a very basic Docker lab to build out confidence.
- Two plain Nginx containers.
- Run them on a bridge called test-radiusdesk
- Reach them on ports 8000 and 8001 respectively from the host Linux system laptop running Docker.
1. Create the bridge
- Create the bridge
docker network create test-radiusdesk
#This was the result
f67e11184a174cf7fb82ba85734dd6d895f0690738cb07246fd7ee13b0024761
- Confirm it was created:
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
- If you issue the ip a command it will be listed there (Look for the NETWORK ID)
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
- Issue the following commands (We will use docker up first)
# 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
- What that does:
- –network test-radiusdesk plugs both into your custom bridge
- -p 8000:80 means laptop port 8000 forwards to container port 80
3. Test from your laptop
- Use curl or your browser
curl http://localhost:8000 curl http://localhost:8001
- Both should show “Welcome to nginx!”
4. Prove they can talk to each other by name (the bridge magic)
- Issue this command:
docker exec -it nginx-8000 ping nginx-8001
- It will resolve! On the default bridge this would NOT work.
- Another test:
docker exec -it nginx-8000 curl http://nginx-8001
- Container 8000 reaching container 8001 internally on port 80, without going through your host ports.