How To Create and Use Volumes?
- Start the docker environment.
sudo systemctl start docker
- Check for images which is to be containerize.
docker pull *image_name*
For Example:
docker images
- Create a volume.
docker volume create *volume_name*
- Run a Docker container with the volume attached:
docker run -d -v *volume_name*:/path/in/container –name *container_name* *image_name*
Replace /path/in/container
with the path within the container where you want to store the data.
- Data will remain accessible even if the container is terminated or removed thanks to Docker’s management of the volume’s persistence.
For Example:- Create a file to be stored in the volume inside the running container.
Check whether file is created in the container i.e.
(
pycontainer
holding
my_volume
)
On terminating the pycontainer it should not affect the volume and it’s storage
Running and accessing the volume i.e., my_volume in another container i.e., swiftcontainer with a new image i.e, swift
Accessing the volume on the local system:
On heading to the Mountpoint address we can access the data in the volume, irrespective of the containers
- When the container has to be updated or changed, you can halt the process and delete the old container:
docker stop *container_name*
docker rm *container_name*
- Remove or Delete the volume
docker volume rm *volume_name*
Now, you can easily access and run the stateful applications on to the volumes and containerize them.
How to Use Docker For Stateful Applications with Persistent Volumes?
Data persistence is provided through a controlled directory called a Docker Volume, which may be mounted inside Docker containers. When containers are stopped or deleted, it enables data to continue to exist. Volumes can be shared across containers and are unaffected by container lifecycles. They make data management and integrity maintenance in Dockerized environments simpler by giving stateful apps a dependable means to store and retrieve data.
Persistent volumes (PVs), a component of container orchestration platforms like Kubernetes, offer programmes reliable and independent storage. Data persists even after pods or containers are terminated because of PVs’ separation of storage from the application lifecycle. Different types of storage resources may be supplied and managed thanks to their features, which include replication, access modes, and storage classes. Data persistence and availability across container instances and deployments are made possible by the use of persistent volumes, which provide applications access to dependable, long-term storage that is independent of the underlying infrastructure.