Saturday, April 18, 2020

Docker Assignments #3: User Defined Bridge Network

  1. Create user defined bridge network (i.e. let us name it as 'testnetwork')
  2. List all available networks under docker host
  3. Create two alpine containers (i.e. let us name it as 'alpine1' and 'alpine2' )  by mapping them to user defined bridge network ( i.e. testnetwork) 
  4. Verify if both containers are associated with the bridge network
  5. Get IP-addresses of both containers
  6. Enter into 'alpine2' container by interactivemode
  7. ping 'alpine1' container using IP-address 
  8. ping 'alpine1' container using container name
  9. Enter into 'alpine1' container by interactivemode
  10. ping 'alpine2' container using IP-address 
  11. ping 'alpine2' container using container name
  12. create alpine3 container with both default bridge network and user defined bridge network
  13. Verify alpine3 container is associated with both default bridge network and user defined bridge network
  14. Observe the difference between default bridge network and user-defined bridge network
Step 1:
  Use below command to create user defined bridge network
     > docker network create --driver bridge testnetwork     

Step 2: 
     > docker network ls 

Step 3: 
     > docker run -itd --network testnetwork --name alpine1 alpine 
     > docker run -itd --network testnetwork --name alpine2 alpine  

Step 4:
Use below command to check both containers are associated with testnetwork
    > docker inspect testnetwork

Step 5:
    use below command to get container IP-address
     > docker inspect alpine1
     > docker inspect alpine2

Step 6:
  Use below command to enter running container using interactive mode
     > docker exec -it alpine2 sh

Step 7:  
    Ping alpine1 container using IP-address
      # ping -c 2 172.18.0.2  (i.e. ping will be successful )

Step 8:  
  Ping alpine1 container using name
      # ping -c 2 alpine1  (i.e. ping will be successful )

Step 9:
  Use below command to enter running container using interactive mode
     > docker exec -it alpine1 sh

Step 10:  
    Ping alpine2 container using IP-address
      # ping -c 2 172.18.0.3  (i.e. ping will be successful )

Step 11:  
  Ping alpine2 container using name
      # ping -c 2 alpine2  (i.e. ping will be successful )

Step 12: 
     > docker run -itd --network testnetwork --name alpine3 alpine 
     > docker network connect bridge alpine3

Step 13: 
     > docker inspect alpine3 

Step 14: 
  1. On a user-defined bridge network, containers can resolve each other by name without linking
  2. Using a user-defined network provides a scoped network in which only containers attached to that network are able to communicate
  3. Containers can be attached and detached from user-defined networks on the fly
  4. ENV variables can't be shared by using user-defined bridge network.
  5. On a default bridge network, ENV variables will be shared across linked containers 
Happy Coding :)
     

No comments:

Post a Comment