Wednesday, October 11, 2023
HomeCloud ComputingThe right way to Create and Use a Docker Quantity (+ Video...

The right way to Create and Use a Docker Quantity (+ Video Tutorial)

Advertisement


On this The right way to Make Tech Work tutorial, Jack Wallen exhibits the right way to create a Docker quantity that can be utilized for any variety of containers.

A Docker quantity is a useful option to deploy a container with persistent storage or to share knowledge between two containers. With this useful trick, you might deploy a number of web sites that use the identical quantity housing their knowledge. It’s an important function that helps to provide Docker extra flexibility. I wish to present you the right way to create and use a Docker quantity, so you possibly can take pleasure in simplified knowledge sharing and protracted knowledge together with your containers.

Advertisement

The very first thing you could do is create a brand new quantity. Let’s name it shared-data, and the command for this may 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 are able to create a file within the shared listing with the command

echo "Good day, TechRepublic" >> /shared-data/check.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 check.txt file that was saved inside the quantity. Check that with the command

cat /shared-data/check.txt

and it is best to see Good day, TechRepublic.

Congratulations! You might have 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 keen on studying extra about Docker, try the next sources in TechRepublic Academy:

Advertisement
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments