Docker - Data and Volumes
Docker - Data and Volumes
Types of data
Container and Image Data
Container Data
Data can be stored inside containers as files, just as you would normally do on your local development machine.
However, once a container is removed, the data will be lost.
Volumes
- Volumes are folders on your host machine hard drive which are mounted (“made available”, mapped) into containers.
- Volumes persist if a container shuts down. If a container (re-)starts and mounts a volume, any data inside of that volume is available in the container.
- A container can write data into a volume and read data from it.
Defining Volumes
The VOLUME command specifies a path inside the container that will be treated as a volume. The mapping to the host’s file system is defined by the run command when starting a container.
Volumes & Bind Mounts
Volumes vs. Bind Mounts
Container / Volume Interaction
Summary
- Containers can read + write data. Volumes can help with data storage, Bind Mounts can help with direct container interaction.
- Containers can read + write data, but written data is lost if the container is removed.
- Volumes are folders on the host machine, managed by Docker, which are mounted into the container.
- Named Volumes survive container removal and can therefore be used to store persistent data.
- Anonymous Volumes are attached to a container - they can be used to save (temporary) data inside the container.
- Bind Mounts are folders on the host machine which are specified by the user and mounted into containers - like Named Volumes.