Docker Volume - Create

Create new Volume using the below command

gaurav@learning-ocean:~$ docker volume ls #list the volume
DRIVER    VOLUME NAME
gaurav@learning-ocean:~$ docker volume create gaurav #create a volume
gaurav

Now, we'll see how we can mount the volume on a directory without creating a new volume. Let's see what all volumes are present right now-

gaurav@learning-ocean:~$ docker volume ls
DRIVER    VOLUME NAME
local     gaurav

Here we don't have any volumes with the name abc. So to create a volume and also mounts it simultaneously, we can use below command-

gaurav@learning-ocean:~$ docker container run -d --name xyz_com_database12 -v abc:/var/lib/mysql -e MYSQL_ALLOW_EMPTY_PASSWORD=true mysql
9fac9587edfd351f5dc42aadad9d6619f9fa77ae439357d86454f6f7b761bb65
gaurav@learning-ocean:~$

This create the volume with name abc and mounts it on the location /var/lib/mysql

gaurav@learning-ocean:~$ docker volume ls
DRIVER    VOLUME NAME
local     abc
local     gaurav
gaurav@learning-ocean:~$