How to use Volumes With Docker Compose In Docker
In Docker Compose, volumes may also be defined and utilised. Create a top-level volumes field in your docker-compose.yml file, identify the volumes you want to create, then mount your volumes into your containers in the services section:
services:
app:
image: app-image:latest
volumes:
- app_data:/data
volumes:
app_data:
- To use an already-existing volume, include it in the docker-compose.yml file’s volumes section and set the external flag to true:
volumes:
demo_volume:
external: true
So this is the volume of the docker. We saw that Docker typically starts a container with a blank filesystem, but that data may be stored for a longer period of time than the container’s lifetime thanks to bind mounts and volumes.We learned how to use the command line to attach volumes to an active container as well as how to list and manage Docker volumes.
What Is Docker Volume?
Docker containers enable apps to execute in an isolated environment. All modifications made inside the container are lost by default when it ends. Docker volumes and bind mounts can be useful for storing data in between runs. One way to store data outside of containers is with volumes. All volumes are kept in a specific directory on your host, typically /var/lib/docker/volumes for Linux systems, and are controlled by Docker.