DevOps Classroom notes 16/Dec/2025

Networking in docker

  • Docker networking model follows a specification called as CNM (Container Networking Model)
  • Docker networking supports
    • Single Host
    • Multi Host
  • Lets Discuss Single Host
  • Docker supports Network drivers. The network drivers are
    • Null
    • HOST
    • BRIDGE
    • OVERLAY (multihost)
  • Creating a bridge network
docker network create -d bridge --subnet 10.255.0.0/24 my_bridge
  • running the container on the created network
docker run -d -P  --net my_bridge  nginx
  • All the containers attached a same network can communicate with each other using ip addresses.
  • Lets create two containers in default bridge
docker run -d --name b1 alpine sleep 1d
docker run -d --name b2 alpine sleep 1d
  • Lets get ipaddress of b1 and b2
docker network inspect bridge
  • we got ips as 172.17.0.2 and 172.17.0.3
  • lets ping b2 from b1 using ip
    Preview
  • lets ping b2 from b1 using name
    Preview
  • Lets create two containers in custom bridge
docker run -d --name c1 --net my_bridge alpine sleep 1d
docker run -d --name c2 --net my_bridge alpine sleep 1d
  • Lets get ip address of c1 and c2
docker network inspect my_bridge
  • we got 10.255.0.2 and 10.255.0.3
  • lets ping c2 from c1 using ip and name
    Preview
  • IN default bridge network, name resolution is not enabled, where as in custom defined bridge network, name resolution is enabled.

Lets create a database and application.

  • Create a bridge network
docker network create -d bridge --subnet 10.200.0.0/24 nop_net
  • create a volume
docker volume create nopdb
  • Now lets create mysql container with name nopdb
docker run -d \
  --name nopdb \
  -v nopdb:/var/lib/mysql \
  -e MYSQL_ROOT_PASSWORD=root123 \
  -e MYSQL_DATABASE=nop \
  -e MYSQL_USER=nop \
  -e MYSQL_PASSWORD=nop \
  --net nop_net \
  mysql:8.0

  • Now lets run nop server shaikkhajaibrahim/june-nop
docker run -d \
   --name nop \
   -P \
   --net nop_net \
   shaikkhajaibrahim/june-nop
  • To simplify executing these many commands docker uses docker compose
  • Refer Here for docker compose referenc
  • create a yaml file with name docker-compose.yml
services:
    db:
      image: mysql:8.0
      environment:
        - MYSQL_ROOT_PASSWORD=root123
        - MYSQL_DATABASE=nop
        - MYSQL_USER=nop
        - MYSQL_PASSWORD=nop
      volumes: 
        - nopdb:/var/lib/mysql
      networks: 
        - nop-net

    nop:
      image: shaikkhajaibrahim/june-nop
      networks: 
        - nop-net
      ports: 
        - 33000:5000
networks:
  nop-net:

volumes:
  nopdb:
  • We would discuss about compose after yaml.

Exercise:

  • I want you to figure out a way to create a container
    • with max of 0.5 cores
    • with max of 256 MiB RAM

Published
Categorized as Uncategorized Tagged

By continuous learner

devops & cloud enthusiastic learner

Leave a Reply

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

Please turn AdBlock off
Animated Social Media Icons by Acurax Responsive Web Designing Company

Discover more from Direct DevOps from Quality Thought

Subscribe now to keep reading and get access to the full archive.

Continue reading

Visit Us On FacebookVisit Us On LinkedinVisit Us On Youtube