Listing Volumes in Docker

docker volume ls command
07 December 2024

Introduction to Docker Commands


Hello dear friends! Today we want to discuss one of the important commands in Docker that relates to managing and listing the volumes associated with containers. With Docker, you can easily run your applications inside containers and this feature has significantly assisted developers in recent years. However, managing volumes is one of the essential needs when using Docker.


Now let’s explore the command docker volume ls. With this command, you can see a list of all volumes defined in Docker. Volumes in Docker allow you to store data without tying it to the lifespan of a container. This means that if your container is deleted, your data will remain intact and you can easily use it again.


The docker volume ls command is simple and functional and acts as a key tool for managing and organizing volumes. For example, you can see which volumes currently exist in your system and when they were created. This information provides you with the capability to make better decisions about managing and cleaning up volumes.


Now that we talked a bit about the command’s significance, let’s review an example code that demonstrates how this command can be used and what its output looks like.


$ docker volume ls
DRIVER VOLUME NAME
local my_volume
local my_other_volume

Code Explanation


This code simply lists all existing volumes in Docker.




Line One:


$ docker volume ls

You can enter this command in your terminal to retrieve the list of volumes.




Line Two:


In this line, you will see that there are different columns. The first column DRIVER indicates the type of volume driver, and the second column VOLUME NAME shows the names of the created volumes.




Subsequent Lines:


Each subsequent line represents a volume that includes its names and associated drivers.


FAQ

?

Why should we use volumes?

?

When should I clean up volumes?

?

Can I attach volumes to multiple containers?