Completek8s Classroomnotes 07/Jul/2023

Docker Volume

  • Docker has volumes types Refer Here

    • bind mount
    • volume mount
    • tmpfs mount
      Preview
      Preview
  • List the volumes and create the mysql contianer, view the volumes after that
    Preview
  • Now remove the container and view the volumes
    Preview
    Preview
  • Lets create a volume called as employee volume
    Preview
  • I will start a mysql container with the following environmental variables and volume mounted to the container on folder /var/lib/mysql
    • root password MYSQL_ROOT_PASSWORD ==> admin@123
    • database MYSQL_DATABASE => employees
    • user MYSQL_USER => lte
    • user password MYSQL_PASSWORD => admin@123
docker container run -d --name empdb -P -e "MYSQL_ROOT_PASSWORD=admin@123" \
    -e "MYSQL_DATABASE=employees" \
    -e "MYSQL_USER=lte" \
    -e "MYSQL_PASSWORD=admin@123" \
    -v employee:/var/lib/mysql \
    mysql:8

Preview
* now lets login into mysql terminal of container and create some tables
docker container exec -it empdb mysql -u lte -p
* Execute the following commands

use employees;
CREATE TABLE Customers
(
  ID int,
  Age int,
  FirstName varchar(20),
  LastName varchar(20)
);
INSERT INTO Customers(ID, FirstName, LastName)
VALUES ('1', 'User', 'Test');
select * from Customers;

Preview
* Now lets delete this container
Preview
* Now lets create a new container with same volume mounted

docker container run -d --name empdbagain -P -e "MYSQL_ROOT_PASSWORD=admin@123" \
    -e "MYSQL_DATABASE=employees" \
    -e "MYSQL_USER=lte" \
    -e "MYSQL_PASSWORD=admin@123" \
    -v employee:/var/lib/mysql \
    mysql:8
  • Now query for Customers
    Preview
  • VOLUME instruction in Docker image:

    • While building the docker image if we use the volume instruction with some folder path, volumes will be created if the user doesnot explicitly passes -v or --mount. If -v or –mount are used then data will be used based on the mount passed during container created

Networking in Docker

  • Create a new linux vm and install docker in it
  • execute docker network ls
  • docker implements networking with the help of network drivers Refer Here
  • Docker has came up with specification Container Network Model (CNM) and implemented libnetwork Refer Here whereas there is one more popular container networking specification which is used in kubernetes i.e. Container Network Interface (CNI) Refer Here
  • We will continue this discussion tomorrow

Leave a Reply

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

About continuous learner

devops & cloud enthusiastic learner