DevOps Classroomnotes 19/Jun/2022

Docker Volumes Contd…

  • Bind Mounts:
    • Can be mapped to any where on the host
    • Not Managed by docker
    • So any non-docker process can modify
      Preview
  • Volume:
    • Stored in the hostfile system by default which is managed by Docker
    • Non-Docker processes are not allowed to modify
      Preview
    • Lets create two alpine container and attach docker volume
      Preview
      Preview
      Preview
  • Lets try to create a database container. docker container run -d --name mysql1 -P -e MYSQL_ROOT_PASSWORD=rootroot -e MYSQL_DATABASE=employees mysql:8
  • We can notice a strange volume got created
    Preview
    Preview
  • Generally while we build docker images, if there is any folder that needs to be persisted we can create the VOLUME on container creation automatically by Dockerfile DIRECTIVE called as volume
  • Now lets create a volume and use it while creating docker container for mysql
docker volume create mysql-employees
docker container run -d --name mysql1 -P -e MYSQL_ROOT_PASSWORD=rootroot -e MYSQL_DATABASE=employees --mount type=volume,src=mysql-employees,target=/var/lib/mysql mysql:8
  • Now connect to the database and execute the following
create database ecommerce;
use ecommerce;
create table tblEmployee
(
Employee_id int auto_increment primary key,
Employee_first_name varchar(500) NOT null,
Employee_last_name varchar(500) NOT null,
Employee_Address varchar(1000),
Employee_emailID varchar(500),
Employee_department_ID int default 9,
Employee_Joining_date date 
);

INSERT INTO tblEmployee (employee_first_name, employee_last_name, employee_joining_date) values ('Nisarg','Upadhyay','2020-06-26');
INSERT INTO tblEmployee (employee_first_name, employee_last_name, employee_joining_date) values ('Gopi','s','2020-06-26');
INSERT INTO tblEmployee (employee_first_name, employee_last_name, employee_joining_date) values ('Venkat','Anand','2020-06-26');
INSERT INTO tblEmployee (employee_first_name, employee_last_name, employee_joining_date) values ('Sukhen','Manna','2020-06-26');
INSERT INTO tblEmployee (employee_first_name, employee_last_name, employee_joining_date) values ('Vivek','Mishra','2020-06-26');
Select * from tblEmployee;
  • To connect to mysql without workbench use phymyadmin
docker container run --name myadmin -d -e PMA_HOST=172.17.0.2 -e PMA_USER=root -e PMA_PASSWORD=rootroot -p 8080:80 phpmyadmin

Activity 1

  • Create an nginx container and map 80 port of container to 8080 port of the host
    • Running docker in attached mode
      Preview
    • Running docker containers in detached mode
      Preview
  • Lets execute the pwd in the nginx container that is running
    Preview
  • Since the container is running in the detached mode and now if you want to login into the container using some terminal (-it)
    Preview

Activity 2

  • Create the jenkins/jenkins:latest in the attached mode and see the information. Map the port 8080 of container to any random port
  • Execute ctrl+C to kill the container
  • Now Run the jenkins/jenkins:latest in the detached mode with port 8080 mapped to any random port.
  • Access the application from browser and it will ask to enter some secret from a file inside container try to fetch and run that.
  • Lets create a volume for jenkins home dir and create a jenkins contianer
    Preview
  • Configure jenkins and create a user
    Preview
    Preview
    Preview
  • Now create a new contaier jenkins/jenkins with the same volume attached
  • Now delete both the containers and create the new continer with the same volume attached and login into jenkins
    Preview
  • Lets create a standby jenkins with the max memory limit of 1GB
    Preview
    Preview
  • By default jenkins will pull out all the logs written to stdout and stderr
    Preview

Activity 3

  • Create a postgres container with necessary volumes and insert some data and verify
  • Create a mongodb container with necessary volumes and insert some data and verify
  • what is -u in the image below
    Preview
  • TRY to create a docker image with ubuntu as base image and default username is qtdevops (HINT: Look at USER directive in Dockerfile) and the default directory to when we execute pwd should /tmp/ (HINT: Look at WORKDIR directive in Dockerfile)

Leave a Reply

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

About continuous learner

devops & cloud enthusiastic learner