- Create user defined bridge network (i.e. let us name it as 'testnetwork')
- List all available networks under docker host
- 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)
- Verify if both containers are associated with the bridge network
- Get IP-addresses of both containers
- Enter into 'alpine2' container by interactivemode
- ping 'alpine1' container using IP-address
- ping 'alpine1' container using container name
- Enter into 'alpine1' container by interactivemode
- ping 'alpine2' container using IP-address
- ping 'alpine2' container using container name
- create alpine3 container with both default bridge network and user defined bridge network
- Verify alpine3 container is associated with both default bridge network and user defined bridge network
- 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
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:
- On a user-defined bridge network, containers can resolve each other by name without linking
- Using a user-defined network provides a scoped network in which only containers attached to that network are able to communicate
- Containers can be attached and detached from user-defined networks on the fly
- ENV variables can't be shared by using user-defined bridge network.
- On a default bridge network, ENV variables will be shared across linked containers
Happy Coding :)
No comments:
Post a Comment