Docker volume: Theory
https://muhammadbasirbaig.medium.com/types-of-volumes-in-docker-9ddc84d6f5d9#:~:text=%20Types%20Of%20Volumes%20In%20Docker%20%201,if%20the%20data%20is%20only%20going...%20More%20
[root@ip-172-31-39-133 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mysql latest 70325c69f1fe 3 days ago 447MB
----
docker image inspect mysql
"Image": "sha256:70085967b5e8a570f801bad787ac3551abe82bd06aeeae4acc402c5f8f706948",
"Volumes": {
"/var/lib/mysql": {}
=---------------
[root@ip-172-31-39-133 ~]# docker container run -d --name mysql_demo -e MYSQL_ALLOW_EMPTY_PASSWORD=true mysql
fc9adc908367882debb884010f4093c56071df898924b21c1b187a36f253f731
[root@ip-172-31-39-133 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
fc9adc908367 mysql "docker-entrypoint.s…" 6 seconds ago Up 5 seconds 3306/tcp, 33060/tcp mysql_demo
2ba149181b54 nginx "/docker-entrypoint.…" 14 hours ago Up 14 hours 80/tcp elegant_cray
[root@ip-172-31-39-133 ~]#
[root@ip-172-31-39-133 ~]# docker volume ls
DRIVER VOLUME NAME
local 83a13c22bec37287e671d8654b8fb8b19c48cbcc338a7f7ea54772ce1b71dd33
[root@ip-172-31-39-133 ~]#
[root@ip-172-31-39-133 _data]# pwd
/var/lib/docker/volumes/83a13c22bec37287e671d8654b8fb8b19c48cbcc338a7f7ea54772ce1b71dd33/_data
[root@ip-172-31-39-133 dockerdemo]# docker container exec -it fc9adc908367 bash
bash-4.4# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.30 MySQL Community Server - GPL
Copyright (c) 2000, 2022, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.01 sec)
mysql> create database kishor
-> ;
Query OK, 1 row affected (0.01 sec)
mysql> create database satish
-> ;
Query OK, 1 row affected (0.01 sec)
mysql> create database satish
-> ;
ERROR 1007 (HY000): Can't create database 'satish'; database exists
mysql> create database ganesh;
Query OK, 1 row affected (0.01 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| ganesh |
| information_schema |
| kishor |
| mysql |
| performance_schema |
| satish |
| sys |
+--------------------+
7 rows in set (0.00 sec)
-------------
created new container:
[root@ip-172-31-39-133 dockerdemo]# docker container run -d --name mysql_demo -e MYSQL_ALLOW_EMPTY_PASSWORD=true mysql
54e7eace755057e125576b84098cbcd1eb2b44e878d932b8e8221dc23cbab6d2
[root@ip-172-31-39-133 dockerdemo]# docker exec -it 54e bash
bash-4.4# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.30 MySQL Community Server - GPL
Copyright (c) 2000, 2022, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
mysql>
================
[root@ip-172-31-39-133 dockerdemo]# docker run -itd -v 83a13c22bec37287e671d8654b8fb8b19c48cbcc338a7f7ea54772ce1b71dd33:/var/lib/mysql mysql
85901506b9ae2bab09c8a104b49d63db0a083e3dac5674c464d88d526e00ad69
[root@ip-172-31-39-133 dockerdemo]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
85901506b9ae mysql "docker-entrypoint.s…" 5 seconds ago Up 4 seconds 3306/tcp, 33060/tcp elated_jemison
54e7eace7550 mysql "docker-entrypoint.s…" 10 minutes ago Up 10 minutes 3306/tcp, 33060/tcp mysql_demo
[root@ip-172-31-39-133 dockerdemo]# docker exec -it 85901506b9ae bash
bash-4.4# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.30 MySQL Community Server - GPL
Copyright (c) 2000, 2022, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| ganesh |
| information_schema |
| kishor |
| mysql |
| performance_schema |
| satish |
| sys |
+--------------------+
7 rows in set (0.15 sec)
mysql>
=============
[root@ip-172-31-39-133 ~]# docker volume create myvol
myvol
[root@ip-172-31-39-133 ~]# cd /var/lib/docker/volumes/
[root@ip-172-31-39-133 volumes]# ls -l
total 24
drwx-----x 3 root root 19 Aug 30 18:30 83a13c22bec37287e671d8654b8fb8b19c48cbcc338a7f7ea54772ce1b71dd33
drwx-----x 3 root root 19 Aug 30 18:36 8db408011f86a213df2975039da6177698f5cfcd9a8451d9b3bf54003fae502b
brw------- 1 root root 202, 1 Aug 30 18:58 backingFsBlockDev
-rw------- 1 root root 32768 Aug 30 18:59 metadata.db
drwx-----x 3 root root 19 Aug 30 18:59 myvol
drwx-----x 3 root root 19 Aug 30 18:50 test
[root@ip-172-31-39-133 volumes]# docker volume create myvol1
myvol1
[root@ip-172-31-39-133 volumes]# docker volume create myvol2
myvol2
[root@ip-172-31-39-133 volumes]# docker volume ls
DRIVER VOLUME NAME
local 8db408011f86a213df2975039da6177698f5cfcd9a8451d9b3bf54003fae502b
local 83a13c22bec37287e671d8654b8fb8b19c48cbcc338a7f7ea54772ce1b71dd33
local myvol
local myvol1
local myvol2
local test
-----------
Remove Volume:
[root@ip-172-31-39-133 volumes]# docker volume rm myvol2
myvol2
Prune Volume: Remove un used volume:
[root@ip-172-31-39-133 volumes]# docker volume prune
WARNING! This will remove all local volumes not used by at least one container.
Are you sure you want to continue? [y/N] y
Deleted Volumes:
myvol
myvol1
Total reclaimed space: 0B
[root@ip-172-31-39-133 volumes]#
==================
https://dockerlabs.collabnix.com/beginners/volume/create-a-volume-mount-from-dockerfile.html
==============
Bind Mount:
[root@ip-172-31-39-133 volumes]# cd /dockerdemo/
[root@ip-172-31-39-133 dockerdemo]# ls -l
total 114296
-rw-r--r-- 1 root root 34 Aug 30 04:36 Dockerfile
-rw-r--r-- 1 root root 117034496 Aug 30 03:53 mycon.tar
[root@ip-172-31-39-133 dockerdemo]# pwd
/dockerdemo
[root@ip-172-31-39-133 dockerdemo]# docker run -it -v /dockerdemo:/tmp/test ubuntu bash
root@5d3b1c485eb1:/# ls -l /tmp/test/
total 114296
-rw-r--r-- 1 root root 34 Aug 30 04:36 Dockerfile
-rw-r--r-- 1 root root 117034496 Aug 30 03:53 mycon.tar
root@5d3b1c485eb1:/#
---------------
Docker Network:
https://docs.docker.com/engine/reference/commandline/network/
https://monkelite.com/introduction-to-docker-networking/
No comments:
Post a Comment