Docker Volume
-
Docker has volumes types Refer Here
- bind mount
- volume mount
- tmpfs mount
-
List the volumes and create the mysql contianer, view the volumes after that
-
Now remove the container and view the volumes
-
Lets create a volume called as employee volume
- 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
- root password
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
* 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;
* Now lets delete this container
* 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
-
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
- 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
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