Volumes are additional R/W Layers external to running container. Deleting a container would not affect a volume.
Volume mounting uses switch "-v" with syntax: docker run -v "hostdir":"guestdir":mode ... IMAGENAME
Note: hostdir is Fully Qualified Directory Path on Host systems guestdir is Fully Qualified Directory Path on Container File system mode could be RW (default: ReadWrite) or RO (ReadOnly)
```bash
$ mkdir -p db/data
$ docker run -d
-e MYSQL_USER=mahendra -e MYSQL_PASSWORD=pass@1234 -e MYSQL_ROOT_PASSWORD=Pass@1234
-e MYSQL_DATABASE=XBankDB -v /home/mahendra/db/data:/var/lib/mysql
-p 3306:3306 mysql:5.7
```
```pwsh
$ mkdir -p c:/db/data
$ docker run -d
-e MYSQL_USER=mahendra -e MYSQL_PASSWORD=pass@1234 -e MYSQL_ROOT_PASSWORD=Pass@1234
-e MYSQL_DATABASE=XBankDB -v c:/db/data:/var/lib/mysql
-p 3306:3306 mysql:5.7
```
NOTE: Windows would prompt you to enter ADMIN USERNAME & PASSWORD for allowing disk access to HyperV (DockerDesktopVM)
```
$ docker top <CONTAINER-ID>
$ docker logs <CONTAINER-ID>
$ docker exec -it <CONTAINER-ID> bash
$ mysql -umahendra -ppass@1234
SQL> use XBankDB
SQL> create table account (acc_id int primary key, acc_holder varchar(20));
SQL> insert into account values (10001, 'Nehru');
SQL> COMMIT;
SQL> exit
$ exit
$ docker stop <CONTAINER-ID>
$ docker rm <CONTAINER-ID>
```
```bash
$ mkdir -p db/data
$ docker run -d
-e MYSQL_USER=mahendra -e MYSQL_PASSWORD=pass@1234 -e MYSQL_ROOT_PASSWORD=Pass@1234
-e MYSQL_DATABASE=XBankDB -v /home/mahendra/db/data:/var/lib/mysql
-p 3306:3306 mysql:5.7
```
```pwsh
$ mkdir -p c:/db/data
$ docker run -d
-e MYSQL_USER=mahendra -e MYSQL_PASSWORD=pass@1234 -e MYSQL_ROOT_PASSWORD=Pass@1234
-e MYSQL_DATABASE=XBankDB -v c:/db/data:/var/lib/mysql
-p 3306:3306 mysql:5.7
```
```
$ docker exec -it <CONTAINER-ID> <cmd>
$ mysql -umahendra -ppass@1234
SQL> use XBankDB;
SQL> select * from account;
SQL> exit
$ exit
```
After container was destroyed and re-created, the volume preserved the mysql database!
```
$ docker stop <container-id>
$ docker rm <container-id>
```
NOTE: Please replace every occurrence of with ID of your container