1 00:00:00,001 --> 00:00:01,000 [No Audio] 2 00:00:01,000 --> 00:00:03,834 In this demo, we are going to demonstrate the use 3 00:00:03,834 --> 00:00:06,634 of Volumes which we have discussed in the theory. 4 00:00:07,767 --> 00:00:10,101 Let's start with creating the Volume which we had 5 00:00:10,101 --> 00:00:14,367 deleted in the last demo, which is vol-ubuntu. 6 00:00:14,734 --> 00:00:19,834 We will do it by running a container from ubuntu image called cont-ubuntu. 7 00:00:19,834 --> 00:00:21,934 [No Audio] 8 00:00:21,934 --> 00:00:26,434 Let's see if both the Volume and the container are available. 9 00:00:26,967 --> 00:00:29,534 Again, to remind you, we can always check the 10 00:00:29,534 --> 00:00:32,366 container using docker container inspect command 11 00:00:32,601 --> 00:00:38,067 and find the information about Volume by formatting its output. 12 00:00:38,767 --> 00:00:42,134 As you can see, the container called cont-ubuntu 13 00:00:42,134 --> 00:00:44,967 has the Volume vol-ubuntu attached to it. 14 00:00:45,167 --> 00:00:48,434 Now, let's execute our container 15 00:00:48,434 --> 00:00:51,067 and run bash command on it. 16 00:00:51,567 --> 00:00:55,367 You can notice that we are not executing it as a daemon container, 17 00:00:55,701 --> 00:00:58,534 which means that once this command succeeds, 18 00:00:58,534 --> 00:01:01,867 we will jump right into the terminal of our container. 19 00:01:02,567 --> 00:01:05,101 Right now, this container is in its 20 00:01:05,101 --> 00:01:08,734 default state, which means that even if we delete it 21 00:01:08,734 --> 00:01:12,434 and spin it up, again, nothing will change. 22 00:01:12,534 --> 00:01:15,234 So let's make a few changes to it, which will be 23 00:01:15,234 --> 00:01:18,767 reflected in its read-write topmost layer. 24 00:01:18,767 --> 00:01:22,501 And if we delete the container, then the changes we have 25 00:01:22,501 --> 00:01:26,967 made now, would be lost. The action can be pretty 26 00:01:26,967 --> 00:01:30,234 simple here, we don't need to do something so heavy. 27 00:01:30,434 --> 00:01:33,901 Even a simple act of just updating the OS 28 00:01:33,901 --> 00:01:37,067 can create enough changes to be recognized. 29 00:01:37,067 --> 00:01:41,901 So let's update this Ubuntu by typing apt-get update command. 30 00:01:42,734 --> 00:01:46,467 Once it is updated, let's change our 31 00:01:46,467 --> 00:01:51,001 working directory to var-log. As you may 32 00:01:51,001 --> 00:01:54,067 have guessed, this is the directory where ubuntu 33 00:01:54,067 --> 00:01:55,867 is keeping its logs. 34 00:01:56,634 --> 00:01:59,234 Let's list out the available files 35 00:01:59,401 --> 00:02:01,967 and we have a lot of log files here. 36 00:02:02,101 --> 00:02:06,901 The purpose of doing so is, to make sure that once we 37 00:02:06,901 --> 00:02:09,567 stopped the container, we should be able to see 38 00:02:09,567 --> 00:02:13,567 the same files as backup on our host machine. 39 00:02:13,567 --> 00:02:17,701 And the reason for that is when we created this container, 40 00:02:17,701 --> 00:02:20,734 we had mount this directory to our host 41 00:02:20,734 --> 00:02:23,701 using the Volume val-ubuntu. 42 00:02:25,001 --> 00:02:28,001 Let's exit the process and stop the container. 43 00:02:28,001 --> 00:02:30,501 [No Audio] 44 00:02:30,501 --> 00:02:35,101 Now, let's have the root privileges on our host machine. 45 00:02:36,267 --> 00:02:39,434 And as you can see, we are on the same working 46 00:02:39,434 --> 00:02:42,567 directory just with root privileges. Now, as we 47 00:02:42,567 --> 00:02:45,234 have seen in the theory section of Volumes, 48 00:02:45,234 --> 00:02:48,901 Docker stores the backup of Volume data, 49 00:02:49,001 --> 00:02:54,634 under var-lib-docker-volumes directory. 50 00:02:55,367 --> 00:02:58,767 So let's navigate to it and let's list 51 00:02:58,767 --> 00:03:02,101 out the content in this directory. As you can see, 52 00:03:02,101 --> 00:03:04,801 we have directories of all of the Volumes created 53 00:03:04,801 --> 00:03:08,767 by local Volume driver. Now let's navigate to 54 00:03:08,767 --> 00:03:12,501 va-ubuntu to see if the changes in the log 55 00:03:12,501 --> 00:03:17,067 file are reflected. Once we are in vol-ubuntu directory, 56 00:03:17,067 --> 00:03:21,567 let's see its contents, and what we have is a data directory. 57 00:03:21,567 --> 00:03:25,667 Once we navigate to that, and list its contents 58 00:03:25,867 --> 00:03:29,501 what we see is a long list of log files, 59 00:03:29,801 --> 00:03:32,167 which means that the mounting 60 00:03:32,167 --> 00:03:35,234 of Volume with the container was successful. 61 00:03:35,234 --> 00:03:38,401 So this is how we mount a Volume to a 62 00:03:38,401 --> 00:03:43,234 container and create a backup of its data to host 63 00:03:43,567 --> 00:03:45,567 using local Volume driver