In the previous post we’ve learnt some of the most useful Docker Containers commands. In this post, we’ll investigate volumes in detail and see how we can run either State-full or State-less containers.
Docker Volume is essentially a disk space assigned to your container. All you need to do to use volumes in Docker environment is to declare, or attach it, while creating an instance of container. Alternatively, you can also attach an existing volume at container create time.
You can also create a new instance of a volume on your Docker system, which you’ll then be able to bind to a container. To create one, use the volume create command.
More details: docker volume create cli
docker volume create [VOLUME NAME]
Create Volume with Flags
docker volume create [FLAG] [VOLUME NAME]
|Specify volume driver name
To check what volumes you have already created in your system, use the volume ls command.
More details: docker volume ls cli
docker volume ls
To have a closer look into an instance of a volume for features such as driver, scope or mount point use the volume inspect command.
More details: docker volume inspect cli
docker volume inspect [VOLUME NAME]
It’s always a good idea to remove volume on your Docker system that you don’t need anymore. To do so use the volume rm command.
More details: docker volume rm cli
Remove Volume by Name
docker volume rm [VOLUME NAME]
Force Remove Volume
docker volume rm -f [VOLUME NAME]