DevOps Classroomnotes 02/Sep/2023

Networking in Containers

  • Refer Here for networking series in docker
  • Docker defined a standard for container networking called as Container Networking Model (CNM)
  • CNM is the spec and libnetwork is the implementation

Experiment: Interaction between two containers in default bridge

  • Examine default bridge
    Preview
  • create a container C1 and C2 in default bridge network
docker container run --name C1 -d alpine sleep 1d
docker container run --name C2 -d alpine sleep 1d

Preview
* Now examine default bridge network to find ips of C1 and C2
Preview
Preview
Preview
* Now lets ping C2 from C1 by using ip as well as name
Preview
* Two containers in default bridge are able to communicate with each other using ip addresses but not names i.e. name based resolution is not working
* Now create a new bridge network called as learn-net with cidr range 192.168.100.0/24

docker network create -d bridge --subnet "192.168.100.0/24" learn-net

Preview
Preview
* Now lets create two containers L1 and L2 in the learn-net

docker container run --name L1 --network 'learn-net' -d alpine sleep 1d
docker container run --name L2 --network 'learn-net' -d alpine sleep 1d
  • Now ping L2 from L1 using ip and name
docker container exec L1 ping -c4 L2

Preview
* In user defined bridge network name based as well ip based communication is enabled

Lets Create nop-commerce application by creating volumes and networks

  • Overview
    Preview

steps

  • Create a volume nop-db
docker volume create nop-db
  • Create a network nopnet
docker network create -d bridge --subnet '10.100.100.0/24' nopnet
  • Create a mysql container with username nop, volume, password nop123 in the nopnet with name nopdb
docker container run -d --name nopdb \
    --network nopnet \
    -e "MYSQL_ROOT_PASSWORD=nop123" \
    -e "MYSQL_USER=nop" \
    -e "MYSQL_PASSWORD=nop123" \
    -e "MYSQL_DATABASE=nop" \
    -v nop-db:/var/lib/mysql \
    mysql:8
  • Create the nop container on nopnet
docker container run -d --name nop --network nopnet -P nop

Preview
Preview
* Inspect network
Preview
* Now watch the classroom video to bring up the application
Preview

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

About continuous learner

devops & cloud enthusiastic learner