On this Easy methods to Make Tech Work tutorial, Jack Wallen reveals how you can create a Docker quantity that can be utilized for any variety of containers.
A Docker quantity is a useful method to deploy a container with persistent storage or to share knowledge between two containers. With this useful trick, you would deploy a number of web sites that use the identical quantity housing their knowledge. It’s a fantastic function that helps to offer Docker extra flexibility. I wish to present you how you can create and use a Docker quantity, so you may take pleasure in simplified knowledge sharing and protracted knowledge along with your containers.
The very first thing you should do is create a brand new quantity. Let’s name it shared-data, and the command for this could be
docker quantity create --name shared-data
The listing housing that quantity on Linux is /var/lib/docker/volumes.
Let’s deploy a Ubuntu container that makes use of the brand new quantity with the command
docker run -ti -v shared-data:/shared-data ubuntu
It will land us on the working container’s bash immediate the place we are able to create a file within the shared listing with the command
echo "Hiya, TechRepublic" >> /shared-data/take a look at.txt
Exit from that container, and cease it with the
exit
command.
Let’s deploy a second container that makes use of the identical quantity with the command
docker run -ti -v shared-data:/shared-data ubuntu
It is best to see that the brand new container has the take a look at.txt file that was saved inside the quantity. Check that with the command
cat /shared-data/take a look at.txt
and it’s best to see Hiya, TechRepublic.
Congratulations! You have got simply created your first Docker quantity that can be utilized for any variety of containers.
Subscribe to TechRepublic’s How To Make Tech Work on YouTube for all the newest tech recommendation for enterprise execs from Jack Wallen.
If you’re eager about studying extra about Docker, try the next sources in TechRepublic Academy: