Interconnection between containers (1)

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).

  1. custom network
    docker network create --deiver bridge --subnet 172.22.0.0/24 --gateway 172.22.0.1 mynet

    Check:

    docker network inspect mynet

     

  2. 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

     

  3. test
    docker exec -i b3 bin/sh
    ping -c 3 b2

     

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325304708&siteId=291194637