Suppose we have an application image and a db image. We definitely want the isolation between the application's container and the db's container, but the application can access the db. So we are faced with a problem, how to communicate between containers? This time we discuss the situation between containers of the same host (mainly looking at bridges).
- custom network
docker network create --deiver bridge --subnet 172.22.0.0/24 --gateway 172.22.0.1 mynet
Check:
docker network inspect mynet
- Use a custom network
docker run -t --name b2 --network mynet --ip 172.22.0.2 busybox docker run -t --name b3 --network mynet --ip 172.22.0.3 busybox
- test
docker exec -i b3 bin/sh
ping -c 3 b2