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
    Preview
  • Now delete the container
    Preview
  • Now lets check volumes
    Preview
  • 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

Preview
Preview
* 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
0805ab3734996f2cdb27b2249745cdaeeb797e4574ca45e9daf183963c9943f6
  • 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)
    Preview
  • Create two containers
    Preview
  • Lets find the ipaddress of the containers
docker container inspect c1 => 172.17.0.2
docker container inspect c2 => 172.17.0.3

Preview
* Now lets see if c1 can communicate with c2 or not
Preview
* Experiment Result: We can establish communications between containers using ip addresses but not by names
* Docker Native Network Drivers
* Host
* Bridge
* Overlay
* MACVLAN
* None
* Lets create a Bridge Network
Preview
Preview
* execute ifconfig on docker host
Preview
* Now lets create two containers in the network which we created
Preview
Preview
* Now lets test the connectiviy between two containers
Preview
* 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