Day 19: Docker for DevOps engineer

Accenture
Docker volume:
Docker volumes are a widely used and useful tool for ensuring data persistence while working in containers. Docker volumes are file systems mounted on Docker containers to preserve data generated by the running container.
Use the following command to create and manage Docker volumes outside the scope of any container.
$docker volume create [volume_name]
Docker automatically creates a directory for the volume on the host under the /var/lib/docker/volume/path.
List the volumes
Use the following command to list the volumes.
- $docker volume list
The output displays a list of volumes, specifying their location and their volume name.
Inspect a volume
Use the following command to inspect a volume.
- $docker volume inspect [volume_name]
It lists all the details of a volume, including its location on the host file (mount point), and everything stored within the data volume can also be found in the directory listed under the mount point path.
Remove a volume
To delete a Docker volume, we need to specify its name. Use the following basic command syntax to remove a volume.
- $docker volume rm [volume_name]
Delete All Volumes at Once
Use the below command to delete all unused Docker volumes at once:
- $docker volume prune
You can first create the volume and then start the container or If you are trying to start a container with a volume that doesn't exist, docker will create a volume for you. Suppose you want to mount a volume (say vol1) into /app/ of the container (say mycontainer1).
TASK:
Create a multi-container docker-compose file that will bring UP and bring DOWN containers in a single shot.
steps:
update the system sudo apt-get update
install docker sudo apt-get install docker
install docker-compose sudo apt-get install docker-compose
write docker-compose vi docker-compse.yml(please refer to my last blog for docker-compose.yml)
Use sudo docker-compose up -d to create and start the containers
use sudo docker ps to see the containers running.
sudo docker-compose down command to down all the containers
To create, inspect volume see the below screenshots:



To create a container from volume see the below screenshots:





