Wednesday, 17 July 2019

Docker Command Part-15 By Raj Gupta

If you are going to create a volume that does not exit like below abc...then it will simply going to create a volume with same same

[root@ip-172-31-93-105 ~]# docker volume ls
DRIVER              VOLUME NAME
local               8c275dfbba8a8134169997142989597ca98a91afdc8bcde841e0fa3dea9f6770
local               bcf7678ec0c851930453fad10b43763caebc4c2e71d6c758863484f8060ad96f
local               e700479341274ebe6837f6f4c20f564a6c93d91cf16490c5d825b2081c1ee07f
[root@ip-172-31-93-105 ~]# docker container run -d --name mysql1 -v abc:/var/lib/mysq4 -e MYSQL_ALLOW_EMPTY_PASSWORD=true mysql
8e578149e45721964154480f9b8ca9d4d6132a98623d092a4f3d9ba9c1607090
[root@ip-172-31-93-105 ~]# docker container ls
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                 NAMES
8e578149e457        mysql               "docker-entrypoint.s…"   28 seconds ago      Up 27 seconds       3306/tcp, 33060/tcp   mysql1
[root@ip-172-31-93-105 ~]# docker volume ls
DRIVER              VOLUME NAME
local               488241083b58309e800e51e6e586b5dae695b5969333231c8928d0b7e9cf56f1
local               8c275dfbba8a8134169997142989597ca98a91afdc8bcde841e0fa3dea9f6770
local               abc
local               bcf7678ec0c851930453fad10b43763caebc4c2e71d6c758863484f8060ad96f
local               e700479341274ebe6837f6f4c20f564a6c93d91cf16490c5d825b2081c1ee07f
[root@ip-172-31-93-105 ~]#


----------------------------------------------------------------------------------------------------

To delete or remove the volume used below command 

To delete one by one
[root@ip-172-31-93-105 ~]# docker volume ls
DRIVER              VOLUME NAME
local               488241083b58309e800e51e6e586b5dae695b5969333231c8928d0b7e9cf56f1
local               8c275dfbba8a8134169997142989597ca98a91afdc8bcde841e0fa3dea9f6770
local               abc
local               bcf7678ec0c851930453fad10b43763caebc4c2e71d6c758863484f8060ad96f
local               e700479341274ebe6837f6f4c20f564a6c93d91cf16490c5d825b2081c1ee07f
local               mytest

[root@ip-172-31-93-105 ~]# docker volume rm 488241083b58309e800e51e6e586b5dae695b5969333231c8928d0b7e9cf56f1

488241083b58309e800e51e6e586b5dae695b5969333231c8928d0b7e9cf56f1
[root@ip-172-31-93-105 ~]# docker volume ls
DRIVER              VOLUME NAME
local               8c275dfbba8a8134169997142989597ca98a91afdc8bcde841e0fa3dea9f6770
local               92217cb240d362ca3b62fa07ffebf50e28e67b31f907d8b87e51cceb340cafb2
local               abc
local               bcf7678ec0c851930453fad10b43763caebc4c2e71d6c758863484f8060ad96f
local               e700479341274ebe6837f6f4c20f564a6c93d91cf16490c5d825b2081c1ee07f
local               mytest
local               xyz



To delete more then one at same time
[root@ip-172-31-93-105 ~]# docker volume ls
DRIVER              VOLUME NAME
local               92217cb240d362ca3b62fa07ffebf50e28e67b31f907d8b87e51cceb340cafb2
local               abc
local               bcf7678ec0c851930453fad10b43763caebc4c2e71d6c758863484f8060ad96f
local               e700479341274ebe6837f6f4c20f564a6c93d91cf16490c5d825b2081c1ee07f
local               mytest
local               xyz
[root@ip-172-31-93-105 ~]# docker volume rm abc mytest
abc
mytest
[root@ip-172-31-93-105 ~]# docker volume ls
DRIVER              VOLUME NAME
local               92217cb240d362ca3b62fa07ffebf50e28e67b31f907d8b87e51cceb340cafb2
local               bcf7678ec0c851930453fad10b43763caebc4c2e71d6c758863484f8060ad96f
local               e700479341274ebe6837f6f4c20f564a6c93d91cf16490c5d825b2081c1ee07f
local               xyz


-----------------------------------------------------------------------------------------------------
To delete all unused volume that volume not used by any container use prune command

[root@ip-172-31-93-105 ~]# 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:
bcf7678ec0c851930453fad10b43763caebc4c2e71d6c758863484f8060ad96f

Total reclaimed space: 183.6MB

[root@ip-172-31-93-105 ~]# docker volume ls
DRIVER              VOLUME NAME
local               92217cb240d362ca3b62fa07ffebf50e28e67b31f907d8b87e51cceb340cafb2
local               e700479341274ebe6837f6f4c20f564a6c93d91cf16490c5d825b2081c1ee07f
local               xyz
[root@ip-172-31-93-105 ~]#


-----------------------------------------------------------------------------------------

To remove the used volume of running container ...First we need to kill the container then we need to remove it then only we are able to delete volume


[root@ip-172-31-93-105 ~]# docker container ls
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                 NAMES
ee6ecf5b36f6        mysql               "docker-entrypoint.s…"   33 minutes ago      Up 33 minutes       3306/tcp, 33060/tcp   mysql1
[root@ip-172-31-93-105 ~]# docker container kill ee6ecf5b36f6
ee6ecf5b36f6
[root@ip-172-31-93-105 ~]# docker container ls
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
[root@ip-172-31-93-105 ~]# docker volume ls
DRIVER              VOLUME NAME
local               92217cb240d362ca3b62fa07ffebf50e28e67b31f907d8b87e51cceb340cafb2
local               e700479341274ebe6837f6f4c20f564a6c93d91cf16490c5d825b2081c1ee07f
local               xyz
[root@ip-172-31-93-105 ~]# docker container ls  -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                       PORTS               NAMES
ee6ecf5b36f6        mysql               "docker-entrypoint.s…"   37 minutes ago      Exited (137) 2 minutes ago                       mysql1
52dd7437728e        mysql               "docker-entrypoint.s…"   3 hours ago         Exited (1) 3 hours ago                           admiring_shtern
[root@ip-172-31-93-105 ~]# docker container rm ee6ecf5b36f6 52dd7437728e
ee6ecf5b36f6
52dd7437728e
[root@ip-172-31-93-105 ~]# docker container ls -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
[root@ip-172-31-93-105 ~]# 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:
xyz
92217cb240d362ca3b62fa07ffebf50e28e67b31f907d8b87e51cceb340cafb2
e700479341274ebe6837f6f4c20f564a6c93d91cf16490c5d825b2081c1ee07f

Total reclaimed space: 183.6MB
[root@ip-172-31-93-105 ~]# docker volume ls
DRIVER              VOLUME NAME
[root@ip-172-31-93-105 ~]#




No comments:

Post a Comment