Create a Data Volume and Mount It on a Docker Container Linux Centos

In this blog post, I will show you how to create a data volume on a Docker host running on Linux CentOS.

Using volumes with Docker containers is something any DevOps engineer will have to learn someday.

The reason for that is because containers are not designed to save data except configuration.

Create Volume

I will start by creating a volume using the following docker command.

docker volume create app

I called the volume app.

Deploy Container and Mount Volume

To run a container and attach the volume to it I will use the following command:

docker container run -it -v data:/app centos /bin/bash

Using the above command I mounted the volume into the app directory inside the container.

Any data that I save inside the app directory is kept on the container host after I delete the container.