On this Find out how to Make Tech Work tutorial, Jack Wallen exhibits methods to 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 information between two containers. With this useful trick, you may deploy a number of web sites that use the identical quantity housing their information. It’s an ideal characteristic that helps to present Docker extra flexibility. I wish to present you methods to create and use a Docker quantity, so you may get pleasure from simplified information sharing and chronic information 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 might 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
This can land us on the operating container’s bash immediate the place we will create a file within the shared listing with the command
echo "Good day, 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
You need 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 is best to see Good day, 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.
In case you are desirous about studying extra about Docker, try the next sources in TechRepublic Academy: