What is Docker Volume | How to create Volumes | What is Bind Mount | Docker Storage

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] hello and welcome to this session on docker volumes and this is going to be a very easy and interesting session on understanding and creating docker volumes and a lot of people say docker volumes is one of the advanced topic on Dockers and it should not be included at beginners level however I believe docker volumes is a very important and useful concept and with this session we will make it very easy and interesting and after this session you will be knowing all about volumes and how do we create attach and share volumes so we are going to see what are volumes how to create list and delete volumes how to attach volume to your container and how to share volumes and then we will also see what are bind mounts so in docker whenever you create a container it has to be some place where the data for the container will be stored now in case you do not provide any explicit location for that data to be stored it gets stored within the container and when you delete the container or remove the container the data is also lost however when you work on enterprise projects we want that the data is not lost we can actually remove a container but still persist that data and in case it is required to create more containers with the old data or to share the data between containers it should be possible so before I actually start showing you the commands let me show you this use of volumes so it is used for decoupling containers from the storage so the storage is separated from the container and even if you delete or remove the container the storage is still available or it is used to share volume or the data among different containers we can attach a volume to a container we can delete container but the volume will not be deleted so this is these are the mean advantages or uses of volume and let me start and go to my terminal and let me also split my screen so you can see the nodes as well as the terminal window now I am on a Mac in case you are on Windows you can use your Windows command prompt or your powershell and on linux you can use your linux command line and of course the prerequisite is docker should be installed on your system so you can run the command docker info or docker - v to see the docker is installed and now we will see docker volume so you can run this command or you can say docker volume - - help both will give you the details on docker volume command and it is used like docker volume and the command and these are the options you can do create for creating a volume inspect to inspect the volume you can say LS to list the volumes Troon will remove all unused local volumes and RM will remove one or more volumes so let us see and let us actually create a volume so I will just clear the console and I will say just for reference I will run docker volume and now I will say darker darker volume create and I can give any name I will I am saying my volume one so this is now created and I can use docker volume LS command to list the volume and darker volume inspect command and the volume name to get the details about the volume so this volume is created at this time and this is the mount point so this volume is available here on your system it cannot be edited by the functions locally so that is one of the advantages so this volume is safe now and the name is my volume one now of course if you want to remove the volume you can say docker volume RM and the volume name like my volume one here and if you want to remove all the unused volume you can say docker volume tune and if you say Y it will remove all local well volumes which are not in use by any one of the containers so as of now I will say n I just want to use this volume and let me just verify my volume is available I will say Dhaka volume LS and yes this is available now let us see how can we use this volume so for example I want to start our Jenkins container so what I will do is I will say darker pull Jenkins and of course if you have any problems you can always go to Google and go to docker hub and go to go to repositories and here I will search for Jenkins and I will go to the details now here you can see that pull command is this dockable Jenkins and then you can run the command this to start the container so I will first pull Jenkins image and to save time I will just fast forward this process so the process of pull is complete I will clear the terminal and now I have to start in the container so for that I will say docker run and I will use the - be flag to expose the port's so I am saying 8080 on the local system and 8080 on the server so the port 8080 of the Jenkins server will be exposed at port 8080 on my local system and for the API is we are using 50,000 and I'm exposing the same code here and the image name which is Jenkins now if I run this command it will surely start the Jenkins container and I will be able to have it running on localhost 8080 I can go to the browser and go to localhost 8080 and I will have my Jenkins training however I want to do some changes the first changes I want to give a name to this container so I will say - - name and I will say this is my Jenkins one and now the other thing I want to do is I want to attach a volume so I will say - V flag and here I will give the volume name which is my volume one that I just created and this will correspond to the Jenkins home directory so you can again go to this location and it has also shown you how you can do this so here I am want all the data of Jenkins home to be available in my volume so this is what I will do here okay so what I'm saying here is let me just show you in a proper way here so what I'm saying here is docker run and I'm giving a name to this container and then I am saying - V my volume one this is my volume name and it should get data from where Jenkins home and then the rest of the process and I will just run this so this will start the Jenkins server on a docker container I will just copy this initial admin password and you can see Jenkins is fully up and running if I go to my local host 8080 on the browser I should have my Jenkins up and here I will provide the admin password that I copied and I will say continue and here we are getting a option to install plugins I will just say select plugins to install and I'm saying none to all to save time and I will just skip this process and I will also skip this process and I will just start using Jenkins so the main idea here is to show how can we share the volume so what I'm going to do here is on my Jenkins I will just create a new job I will say this is test job and this is a freestyle job and say okay and here in the description I will just give some build step and I will apply and save okay so if I go to the dashboard you can see on this Jenkins instant I have this test job created okay now what I'm going to do is I'm going to start another Jenkins container so I will go to a new tab of my terminal you can start a new command prompt on windows and here what I'm going to say is I'm going to actually copy the same command to run the Jenkins container here so I will copy it from here and give it here what I'm going to do is I'm going to change the name of the container so this is going to be Jenkins - and here you see I am giving the same volume that I used for my earlier Jenkins container and of course I have to use different ports because it is 88 is already in use by my current Jenkins so I will choose 90 90 and here let me use 60,000 and let me just turn this now this will start another instance of Jenkins or a different docker container with Jenkins and once this is started let us see if the volume is shared between these two which engines or not you can see this Jenkins is fully up and running now let me go to localhost 9090 so I will go to localhost 1990 now and you see it has not given us the initial plug-in screen it is just giving us the login screen and I am going to log in with the user that I had for the my old Jenkins and I will also copy the password of their Jenkins so I'm going to copy the same password and I will just give it here and say login so if this allows us to login that means the data is being shared between these two Jenkins containers and yes it allowed us to lock it and also you can see this has the test job as well here so the data is being shared between this Jenkins container which is running on port 8080 and this Jenkins container which is running on port 99 t so we are able to share the volume between these two containers and the volume will remain intact even if we close any of these containers or even delete or remove the containers we will still have our volume that we can use for any other container as well so you can also use bind mounts so bind mounts means you can actually use a physical location instead of volume so I will copy the same command here for running a Jenkins container and here instead of using a volume so everything is same let me just change the port numbers here let me use 70,000 here and let me use nine one nine one here and the name I will give is Jenkins three and instead of using our volume I am going to use a physical location on my system so I will say users Raghav desktop and I will create a folder Jenkins home so all the data of Jenkins home will get stored here and I will also show you it will be created here on desktop so if I run this some issue so this is invalid host port let me use something else like 40,000 and yes this should run and you can see a Jenkins home folder is created here and if I open this you can see some data is coming here okay so as this is running we will have some data copied here and you can see new files and folders getting added to this folder as our Jenkins containers is getting created so now this is fully up and running this Jenkins container if I go to localhost nine one nine one and yes you can see this is our new instance now we can do the same thing with this as well if you want to create a new container and use the same or data like this Jenkins home which is now available physically on our system we can do that and now if I let me show you I run docker PS command and we can see these three Jenkins containers are running and this is my Jenkins one two and three let me stop these containers I will stop my Jenkins one and I will stop my Jenkins two and I will stop my Jenkins three and let me now again run the command docker PS and you see all the containers are now stopped and if I say docker PS - a to list all the containers you can see these and containers are available but they are stopped so let me also remove there I will say docker Adam my Jenkins one docker RM my Jenkins 2 and docker RM my Jenkins 3 and let me clear the terminal and if I say docker PS - a now you can see there is no container everything is deleted however if I look at the volume and say dock of volume LS you can see my volume 1 is still there and I can use this to create new containers or share the data with any other container you can also say docker volume inspect my volume 1 and you can see all the details are here and also you can see our physical Jenkins home we created is also here in that all the data is here so if you want to create a new Jenkins server on a docker container with the same data with the same jobs plugins you can do this so this is going to be very useful in enterprise level projects so I hope this was very easy and now you understand the concept of docker volumes and you can now use it in your akka projects I hope this all was very useful and interesting to you I will meet you in the next episode of docker thank you for watching [Music] [Music] [Applause] you
Info
Channel: Automation Step by Step
Views: 209,400
Rating: 4.8739119 out of 5
Keywords: what is docker volume, what is bind mount in docker, docker how to create volume, docker how to share volume between containers, docker how to create bind mout, docker how to create local storage, docker storage
Id: VOK06Q4QqvE
Channel Id: undefined
Length: 16min 50sec (1010 seconds)
Published: Mon Jul 09 2018
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.