DevOps Classroomnotes 07/Feb/2022

Docker containers contd

  • In the last session we have create a mysql container using the following command
docker container run --name mysql  -v mysqldb:/var/lib/mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=qwert456 -d mysql
  • Then we create a database employees and couple of tables students and employees
  • Now delete the container
  • Now lets check volumes
  • Now lets create one more mysql container and attach the existing volume
docker container run --name mysql1  -v mysqldb:/var/lib/mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=qwert456 -d mysql

* When we create a volume it tries to store the volume in local system (host) we can install volume plugins where we get volume drivers which can be used to store the data in remote locations as well Refer Here
* To mount the volume we can use -v or –mount

 docker container run --name mysql2 -d --mount "type=volume,src=mysqldb,dst=/var/lib/mysql" -P mysql
  • Bind mount is mount some folder in your local filesystem as a docker volume
docker container run -v /home/qtdevops/logs:/var/log alpine
docker container run --mount "type=bind,src=/home/qtdevops/logs,dest=/var/log" alpine
  • Volume and Bind mounts use the host system’s file system by default to store the contents of a container whereas tmpfs mount uses host system’s memory to store the contents of the container
  • Exercise:
  • Try to create a volume and attach to postgres container
    docker volume create pgsqlvol
    docker container run -v pgsqlvol:/var/lib/postgresql/data -d -P postgres
  • Try to create a volume and attach to the mongodb container
    docker volume create mongodbvol
    docker container run -v mongodbvol:/data/db -d -P mongo
  • Note: While create db containers you need to pass some ENV varaibles as per the documentation in docker hub to set the username, password, default database, root user password etc.

Docker Networking

  • Refer Here for the article on docker networking
  • Docker networking has a network subcommand (like volume)
  • Create two containers
  • Lets find the ipaddress of the containers
docker container inspect c1 =>
docker container inspect c2 =>

* Now lets see if c1 can communicate with c2 or not
* Experiment Result: We can establish communications between containers using ip addresses but not by names
* Docker Native Network Drivers
* Host
* Bridge
* Overlay
* None
* Lets create a Bridge Network
* execute ifconfig on docker host
* Now lets create two containers in the network which we created
* Now lets test the connectiviy between two containers
* Creating custom bridge network helps in resolving containers by their names as well in addition to ip addresses

Leave a Reply

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

About continuous learner

devops & cloud enthusiastic learner