1 00:00:00,001 --> 00:00:01,067 [No Audio] 2 00:00:01,067 --> 00:00:06,067 In this demo, we are going to create a volume using Docker command line 3 00:00:06,601 --> 00:00:09,867 Let's type the command docker volume create, 4 00:00:09,901 --> 00:00:12,167 followed by the name of the volume. 5 00:00:12,334 --> 00:00:16,601 Here, we are naming the Volume vol-busybox. 6 00:00:18,134 --> 00:00:20,734 Once the commands succeeds, we get the 7 00:00:20,734 --> 00:00:24,434 name of the Volume as the nod of it being created. 8 00:00:24,867 --> 00:00:27,501 Before we do anything to this created Volume, 9 00:00:27,567 --> 00:00:30,334 let's create another one, but this time in a bit 10 00:00:30,334 --> 00:00:32,667 different way. Here, we are going to run a 11 00:00:32,667 --> 00:00:36,201 container using ubuntu image and we're going to 12 00:00:36,201 --> 00:00:39,467 mount the Volume vol-ubuntu on the 13 00:00:39,467 --> 00:00:44,567 containers, tmp or temp directory. Again, we will 14 00:00:44,567 --> 00:00:47,367 not do anything with this Volume, since this demo 15 00:00:47,367 --> 00:00:50,801 primarily focuses on creation of the Volumes. 16 00:00:50,901 --> 00:00:55,101 Now let's list the Volumes to see what we have created. 17 00:00:55,134 --> 00:00:58,534 Let's type docker volume ls, and as you 18 00:00:58,534 --> 00:01:01,901 can see, we have four Volumes here. 19 00:01:01,934 --> 00:01:06,334 Two of them are created by us, whereas two of them are created 20 00:01:06,334 --> 00:01:09,034 by Docker using local Volume driver. 21 00:01:09,034 --> 00:01:11,701 Just like every other object which we have created 22 00:01:11,701 --> 00:01:16,401 previously, like images, networks, or containers, 23 00:01:16,967 --> 00:01:20,667 we can also filter the output of the ls command. 24 00:01:20,967 --> 00:01:24,467 Let's type docker volume ls and put the filter of 25 00:01:24,467 --> 00:01:27,901 dangling=true, it means that it will list 26 00:01:27,901 --> 00:01:30,834 the Volumes which are not being mounted to any container. 27 00:01:31,301 --> 00:01:34,967 Here vol-busybox has not been mounted 28 00:01:34,967 --> 00:01:38,867 to any container. Similarly, the one above it, 29 00:01:38,867 --> 00:01:41,267 which is provisioned by Docker is not being 30 00:01:41,267 --> 00:01:46,134 mounted or used currently. Also, we can inspect 31 00:01:46,134 --> 00:01:49,367 our Volume just like every other object by using 32 00:01:49,367 --> 00:01:52,401 docker volume inspect followed by the volume name. 33 00:01:53,334 --> 00:01:56,901 And as you can see, we get the creation timestamp, 34 00:01:57,001 --> 00:02:01,634 Driver type, Labels which are null here, Mountpoint, 35 00:02:02,001 --> 00:02:06,901 Name of the Volume, and Scope which is local. 36 00:02:07,667 --> 00:02:11,201 Now, let's try to remove one of the Volumes which we have created. 37 00:02:11,734 --> 00:02:14,367 Type the command docker volume rm 38 00:02:14,401 --> 00:02:17,134 followed by the Volume name. Here we are using 39 00:02:17,134 --> 00:02:21,567 Volume vol-ubuntu. As you can see, we get 40 00:02:21,567 --> 00:02:25,334 an error response from Docker daemon. It says that 41 00:02:25,334 --> 00:02:28,734 this Volume can not be removed because it is in use, 42 00:02:28,734 --> 00:02:31,601 which means it has been mount to a container. 43 00:02:31,601 --> 00:02:33,567 So if we remove the Volume, 44 00:02:33,567 --> 00:02:36,601 the container and its performance will be affected. 45 00:02:36,701 --> 00:02:39,267 Let's get a list of containers to see which 46 00:02:39,267 --> 00:02:43,601 container is blocking or action of removing the Volume. 47 00:02:44,267 --> 00:02:47,334 And as you can see, the tender_noyce 48 00:02:47,334 --> 00:02:50,034 container which is built from the ubuntu image, 49 00:02:50,234 --> 00:02:53,967 just two minutes ago, has been mount with the 50 00:02:53,967 --> 00:02:57,801 Volume vol-ubuntu. Although it has not 51 00:02:57,801 --> 00:03:01,101 been mentioned here, you can guess it since all the 52 00:03:01,101 --> 00:03:04,401 other containers are up for more than an hour ago. 53 00:03:04,667 --> 00:03:07,467 Let's type the command docker container rm 54 00:03:07,501 --> 00:03:11,367 followed by its name and tender_noyce is removed. 55 00:03:12,667 --> 00:03:17,801 Now let's rerun the command docker volume rm vol-ubuntu.a 56 00:03:19,201 --> 00:03:21,701 This time, we didn't see any error 57 00:03:21,834 --> 00:03:24,801 and the Volume should have been removed. 58 00:03:25,034 --> 00:03:28,501 Let's verify it by listing the Volumes again. 59 00:03:28,601 --> 00:03:32,901 And yes, the vol-ubuntu is not visible