Skip to main content

Command Palette

Search for a command to run...

Day 19: Docker for DevOps engineer

Published
2 min read
Day 19: Docker for DevOps engineer

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.

  1. $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.

  1. $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.

  1. $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.

  1. $docker volume rm [volume_name]

Delete All Volumes at Once

Use the below command to delete all unused Docker volumes at once:

  1. $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:

  1. update the system sudo apt-get update

  2. install docker sudo apt-get install docker

  3. install docker-compose sudo apt-get install docker-compose

  4. write docker-compose vi docker-compse.yml(please refer to my last blog for docker-compose.yml)

  5. Use sudo docker-compose up -d to create and start the containers

  6. use sudo docker ps to see the containers running.

  7. 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: