1 00:00:00,401 --> 00:00:03,634 In this demo, we will test the Bind Mounts. 2 00:00:03,634 --> 00:00:07,567 Let's create a directory called bind-data on our Docker 3 00:00:07,567 --> 00:00:11,334 host's home directory. Now run a container called 4 00:00:11,334 --> 00:00:15,301 bind-ubuntu from ubuntu:latest image and bind its 5 00:00:15,301 --> 00:00:20,367 tmp or temp directory to the newly created bind-data directory 6 00:00:20,367 --> 00:00:24,501 using bind-mount. As usual, let's 7 00:00:24,501 --> 00:00:27,634 see if the container is running. Yes it is. 8 00:00:27,634 --> 00:00:30,901 Now it is time to inspect the bind-mount information, 9 00:00:30,901 --> 00:00:34,701 and we have Mount Type, which is bind mount along with 10 00:00:34,701 --> 00:00:38,067 Source and Destination paths, which are just as we 11 00:00:38,067 --> 00:00:41,567 had provided them. Furthermore, we have read/write 12 00:00:41,567 --> 00:00:45,634 permission set up to true, which means changes in 13 00:00:45,634 --> 00:00:48,601 the files will reflect on both the sides. 14 00:00:48,601 --> 00:00:51,267 It is probably the least secure way to mount your 15 00:00:51,267 --> 00:00:54,434 container data to persistent storage, but for now, 16 00:00:54,434 --> 00:00:58,134 it works. Lastly, we have bind Propagation, 17 00:00:58,134 --> 00:01:01,534 it is an interesting aspect. Bind Propagation is a 18 00:01:01,534 --> 00:01:04,766 policy which determines the bilateral access to 19 00:01:04,766 --> 00:01:07,267 the directories created within the mount point 20 00:01:07,267 --> 00:01:10,834 source and destinations. In other words, it will 21 00:01:10,834 --> 00:01:13,767 decide whether subdirectories of Mount will be 22 00:01:13,767 --> 00:01:16,967 associated with a mount or not, 'rprivate' is the 23 00:01:16,967 --> 00:01:19,834 default value, which means that any subdirectory 24 00:01:19,834 --> 00:01:22,867 within source or destination of Mount will not 25 00:01:22,867 --> 00:01:26,801 reflect on either side. Let's execute bind-ubuntu 26 00:01:26,801 --> 00:01:30,034 container with bash command and create a file 27 00:01:30,101 --> 00:01:33,967 called foo.txt. We are creating it within the 28 00:01:33,967 --> 00:01:37,734 container's tmp directory which is the mount destination. 29 00:01:37,734 --> 00:01:40,534 Once we are done let's exit the container. 30 00:01:40,534 --> 00:01:42,901 Now let's access the source of mount 31 00:01:42,934 --> 00:01:46,334 point which is within home directory of Docker host. 32 00:01:46,334 --> 00:01:48,667 We can see the bind-data directory 33 00:01:48,667 --> 00:01:53,601 reflecting here, let's open it. And there we go, 34 00:01:53,667 --> 00:01:57,467 foo.txt is present. Now let's try making 35 00:01:57,467 --> 00:02:00,334 changes the other way around. We have seen 36 00:02:00,334 --> 00:02:03,301 destinations update reflecting on source. 37 00:02:03,301 --> 00:02:06,834 Now let's update source to see if destination reflects 38 00:02:06,834 --> 00:02:10,167 the changes as well. Mind well that our container 39 00:02:10,167 --> 00:02:13,267 is shut at the moment and we are creating a new 40 00:02:13,267 --> 00:02:15,767 file called hello.txt. 41 00:02:15,967 --> 00:02:20,201 Let's go back to terminal and execute the container again so that 42 00:02:20,201 --> 00:02:24,367 we can navigate to its tmp or temp directory, hit ls 43 00:02:24,367 --> 00:02:27,567 to see the list of files, and there we go. We had 44 00:02:27,567 --> 00:02:32,201 stopped the container with one file, but now it has two of them 45 00:02:32,201 --> 00:02:34,967 or bind-mount is working successfully.