Learn
WebsiteLoginFree Trial
  • Incident Management
    • What is Incident Management? Beginner's Guide
    • Severity Levels
    • How to calculate MTTR and Other Common Incident Recovery Metrics
    • On-Call
    • SLA vs SLO vs SLI: What's The Difference?
    • Data Aggregation and Aggregators
  • DevOps
    • Best DevOps Tools for Each Phase of the DevOps Lifecycle
      • Best DevOps Planning Tools
      • Best DevOps Coding Tools
      • Best DevOps Build Tools
      • Best DevOps Testing Tools
      • Best DevOps Release Tools
      • Best DevOps Deployment Tools
      • Best DevOps Operations Tools
      • Best DevOps Monitroing Tools
    • What is DevOps?
      • Best CI/CD Tools
      • DevOps Infrastructure and Automation
      • What is a DevOps Pipeline?
      • DevOps Vs. Agile
      • Top 25 DevOps Interview Questions
      • What Are the Benefits of DevOps?
      • What is CI/CD?
      • What is a DevOps Engineer?
      • What is DevSecOps?
    • What is Observability?
      • USE and RED Method
    • What is Site Reliability Engineering (SRE)?
      • Four Golden Signals: SRE Monitoring
      • What is A Canary Deployment?
      • What is Blue-Green Deployment?
  • Docker
    • Overview
    • Dockerfile
    • Images
    • Containers
    • Storage
    • Network
    • Compose
    • Swarm
    • Resources
  • prometheus
    • Overview
    • Data Model
    • Metric Types
    • PromQL
      • Series Selection
      • Counter Rates & Increases
    • Pushgateway
    • Alertmanager
    • Remote Storage
Powered by GitBook
On this page
  • Persistent Storage
  • Volumes
  • Bind Mounts
  • Temporary Storage
  • tmpfs Mounts
  • Frequently Asked Questions
  • How do I Create a Docker Volume?
  • How to Mount a Docker Volume?
  • Where Are Docker Volumes Stored?
  • Can Multiple Containers Mount to the Same Volume?
  • What Are Storage Drivers?
  • Are Docker Volumes Persistent?
  • Docker Volumes with Compose

Was this helpful?

  1. Docker

Storage

Docker volumes are the preferred way to store persistent container data since they provide efficient performance and are de-coupled from the Docker host.

PreviousContainersNextNetwork

Last updated 1 year ago

Was this helpful?

By default, data in is only preserved for the duration of the container's lifespan; once the container is removed or destroyed, the data becomes inaccessible. Thus, persistent storage becomes necessary when you need to retain data beyond the lifespan of a container.

Applications that require data persistence, such as databases, file storage systems, or stateful applications, typically rely on persistent storage to store and retrieve data across container restarts or redeployments.

To ensure the persistence of data beyond the container's lifecycle, Docker offers two persistent solutions:

Persistent Storage

Volumes

are dedicated storage units managed by Docker. Only Docker containers can access volumes.

Volumes are the preferred way to store container data since they provide efficient performance and are de-coupled from the Docker host.

Volumes are independent of the container's lifecycle and can be easily managed, backed up, and replicated. Additionally, volumes can be attached to multiple containers simultaneously to enable sharing of data and files.

Bind Mounts

With bind mounts, changes made to files or directories within the container are reflected on the host and vice versa. Bind mounts provide flexibility but are tightly coupled to the host filesystem.

Temporary Storage

tmpfs Mounts

Frequently Asked Questions

How do I Create a Docker Volume?

docker volume create pg-vol

How to Mount a Docker Volume?

docker run -d \
    --name pg-server \
    --mount source=pg-vol,target=/var/lib/postgresql/data \
    postgres:latest

Where Are Docker Volumes Stored?

Docker volumes are stored in a location managed by Docker, typically within the Docker data directory (default: /var/lib/docker) on the host machine. The specific location depends on the Docker storage driver and configuration settings.

Can Multiple Containers Mount to the Same Volume?

Yes, multiple containers can mount to the same Docker volume simultaneously. This allows multiple containers to share data and collaborate on a common dataset stored in the volume.

What Are Storage Drivers?

Are Docker Volumes Persistent?

Yes, Docker volumes are persistent. They exist independently of the container's lifecycle and are preserved even if the associated container is removed. This makes Docker volumes suitable for storing data that needs to persist across container restarts or redeployments.

Docker Volumes with Compose

In Docker Compose, you can define volumes using the volumes section in your docker-compose.yml file. This allows you to manage volumes and volume mounts declaratively, making it easier to define and configure storage requirements for multi-container applications.

services:
  pg-server:
    image: postgres:latest
    volumes:
      - pg-vol:/var/lib/postgresql/data
volumes:
  pg-vol:

allow you to mount a directory or file from the host machine into a container. Bind mounts can be accessed by both Docker processes and non-Docker processes.

One common scenario where you would use a bind mount is when you are developing a and want to make code changes on your host machine that are immediately reflected within the container without rebuilding the image.

, or temporary filesystems, are temporary storage areas created in a container's memory space. They are helpful for storing transient data or temporary files within a container (think log files or caching). tmpfs is ephemeral and does not persist data across container restarts. Additionally, you can't share tmpfs mounts between containers.

To , you can use the -v or --volume flag with the docker run command, specifying the volume name and mount path within the container.

Alternatively, you can define volume mounts in a Docker Compose file using the volumes section (see below).

extend Docker's native volume functionality by enabling integration with external storage systems or cloud providers. Storage drivers allow you to use specialized storage solutions, such as network-attached storage (NAS), block storage, or cloud storage, as Docker volumes.

Bind mounts
tmpfs mounts
mount a Docker volume
Storage drivers
Docker Volumes with Compose section
Docker containers
Docker volumes
Volumes
Bind Mounts
Dockerized application
Docker Volumes
Docker Bind Mounts
Docker Volumes
Docker Bind Mounts