You are currently viewing How To Create And Manage Docker Volume

How To Create And Manage Docker Volume

How To Create And Manage Docker Volume

Hello Everyone

Welcome to CloudAffaire and this is Debjeet.

In the last blog post, we have discussed the docker network.

https://cloudaffaire.com/how-to-create-and-manage-docker-network/

In this blog post, we will discuss docker volume. We will also create a volume explicitly and attach it to a docker container.

Prerequisite for this demo:

  • One AWS EC2 instance with Linux 2 AMI and internet access.
  • Docker

What is docker volume?

By default, all files created inside a container are stored on a writable container layer. This is great if the file is not required to persist even after the container is stopped. But suppose you have created a database instance inside your container, in that case, you may need a persistent storage option so that you can retrieve the data event when the container is no longer running.

One of the solutions that you can implement for persistent storage is docker volume. By default, docker volumes are created and managed by docker. You can also create a volume explicitly using the docker volume create command, or Docker can create a volume during container or service creation. When you create a volume, it is stored within a directory on the Docker host. When you mount the volume into a container, this directory is what is mounted into the container. This is similar to the way that bind mounts work, except that volumes are managed by Docker and are isolated from the core functionality of the host machine. A given volume can be mounted into multiple containers simultaneously. When no running container is using a volume, the volume is still available to Docker and is not removed automatically.

When you mount a volume, it may be named or anonymous. Anonymous volumes are not given an explicit name when they are first mounted into a container, so Docker gives them a random name that is guaranteed to be unique within a given Docker host. Besides the name, named and anonymous volumes behave in the same ways. Volumes also support the use of volume drivers, which allow you to store your data on remote hosts or cloud providers, among other possibilities.

Next, we are going to create a docker volume and attach it to a container.

How To Create And Manage Docker Volume Demo:

Hope you have enjoyed this article. In the next blog post, we will discuss Dockerfile.

To get more details on docker, please refer below docker documentation

https://docs.docker.com/