Open In App

Docker Volume Commands

Docker volumes are a crucial part in containerized conditions providing a technique to persist and manage information across containers. Basically, a volume in Docker is a catalog (or registry like information) that exists outside the containers’ filesystems however it is open to the container. This partition permits information to persist regardless of whether the compartment is halted or erased, empowering information sharing and perseverance between containers, as well as working with information reinforcement and migration.These commands allows clients to make volumes, list existing volumes, review volume details, and eliminate volumes when they are not generally required. Docker volume commands empower designers and administrators to productively deal with information related tasks inside Docker containers, improving adaptability, unwavering quality, and simplicity and scalability of the board in containerized conditions.

Understanding Docker volume commands is fundamental for Docker users who need to manage information persistency and sharing really inside their containerized applications. By utilizing these commands, clients or users can ensure the data trustworthiness, empower consistent information move among holders, and smooth out the organization and the executives of Docker-based applications.



In this article we will guide you what is docker and what is docker daemon and types of volumes in docker and finally how the docker volume commands works exactly.

What Is docker?

Docker is a platform and toolset that permits you to develop, deploy, and run applications inside containers. containers are lightweight, independent,standalone executable packages that include everything expected to run an application: code, runtime, framework apparatuses, libraries,dependencies and settings. Docker gives a deliberation(abstraction) layer that allows you to package and detach,isolate applications in a consistent manner, no matter what is the underlying infrastructure.



Understanding Of Primary Terminologies Related To Docker

Docker Volumes

There are three main use cases for Docker Volumes as follows:

By Docker Volumes, we are essentially going to look at how to manage data within the docker containers

Types Of Docker Volumes

There are three types of volumes in docker:

1) Named volumes

2) Host bind mounts

3) Anonymous volumes

1. Named volumes

docker run -v name:/path/in/container

2. Host Volumes / Bind Mount

docker run -v /path/on/host:/path/in/container

3. Anonymous Volumes

docker run -v /path/in/container

Implementation Of Docker Volume Commands: A Step-By-Step Guide

Step 1 : Launch Instance In AWS Account

Launch An Instance With Configuration:

ssh -i  "keypair-pem file" ec2-user@<instance-public-ip address>compute-1.amazonaws.com

Step 2: Installing Docker

sudo yum install -y docker

sudo systemctl  start docker
sudo systemctl enable docker
sudo chmod 666 /var/run/docker.sock

In Docker, volumes are a way to persist data generated by and used by Docker containers. They allow data to be stored separately from the container itself, which enables easier management and sharing of data between containers. Here are some common Docker volume commands:

Docker volume Commands

Execute the below docker volume commands for better understanding:

docker volume create

docker volume create my_volume

docker volume ls

docker volume ls

Docker Volume Inspect

docker volume inspect my_volume

Docker Volume rm

docker volume rm my_volume

Docker Volume Prune

docker volume prune

Docker Run -v

docker run -v my_volume:/path/in/container image_name

Docker Run –mount

docker run --mount source=my_volume,target=/path/in/container,readonly image_name

Docker Volume Commands – FAQ’s

How Many Types Of Volumes Are There In Docker?

Docker volumes are used to persist data from within a Docker container

  1. Named volume
  2. Hosts or bind volume
  3. Anonymous volume

Where Are Our Created Docker Volumes Located ?

By default, Docker stores its volumes in the directory located at

cd /var/lib/docker/volumes

How Do I Attach A Docker Volume To A Container?

You can attach a Docker volume to a container when launching the container using the -v or –mount option. These options allow you to specify the volume name and the path within the container where the volume should be mounted.

docker run -v volume_name:/path/in/container image_name

Can We Attach Docker Volume From Container To Another Container?

Yes, you can attach a Docker volume that is already attached to one container to another container without losing data.

by executing this command you will achieve the task

docker run -itd --volumes-from existing_container_name --name new_container_name image_name


Article Tags :