DEV Community

Cover image for Docker Volumes Explained with docker-compose
Athreya aka Maneshwar
Athreya aka Maneshwar

Posted on • Edited on

Docker Volumes Explained with docker-compose

Hello, I'm Maneshwar. I'm building git-lrc, an AI code reviewer that runs on every commit. It is free, unlimited, and source-available on Github. Star Us to help devs discover the project. Do give it a try and share your feedback for improving the product.

Hi there! Right now, I’m building a first-of-its-kind tool that helps you automatically index API endpoints across all your repositories. makes it easier to discover, understand, and interact with APIs in large infrastructures.

When working with containers, managing data is just as important as running the app.

Docker offers multiple ways to handle data persistence and sharing—volumes.

Let’s break down the different types of volumes and how to use them with docker-compose.

1. Named Volumes

Docker manages these under /var/lib/docker/volumes. You define and reference them by name.

Example:

version: '3.8'

services:
  db:
    image: postgres:15
    volumes:
      - pgdata:/var/lib/postgresql/data

volumes:
  pgdata:
Enter fullscreen mode Exit fullscreen mode
  • Volume pgdata will persist even if the container is removed.
  • It can be reused by other services too.

2. Anonymous Volumes

No name given. Docker generates a random volume ID.

Example:

version: '3.8'

services:
  app:
    image: myapp
    volumes:
      - /var/www/data
Enter fullscreen mode Exit fullscreen mode
  • The /var/www/data path in the container is backed by a randomly created volume.
  • These are not easily reusable and can pile up if not managed.

3. Bind Mounts

Mounts a specific path from the host directly into the container.

Example:

version: '3.8'

services:
  web:
    image: nginx
    volumes:
      - ./html:/usr/share/nginx/html:ro
Enter fullscreen mode Exit fullscreen mode
  • Changes on your host (./html) reflect live inside the container.
  • Ideal for local development and live reloading.

4. tmpfs Mounts

A mount in RAM. Fast and volatile—data disappears after container stops.

Example:

version: '3.8'

services:
  scratch:
    image: alpine
    command: sleep 3600
    tmpfs:
      - /tmp/cache
Enter fullscreen mode Exit fullscreen mode
  • Good for scratch space, secrets, build caches, or anything ephemeral.

5. Volume Plugins / External Volumes

For using storage from NFS, cloud providers, etc.

Example with external NFS volume:

version: '3.8'

services:
  app:
    image: myapp
    volumes:
      - nfs-data:/data

volumes:
  nfs-data:
    driver: local
    driver_opts:
      type: nfs
      o: addr=192.168.1.100,rw
      device: ":/exported/path"
Enter fullscreen mode Exit fullscreen mode
  • Useful in cluster setups or multi-host Docker environments.

Quick Recap

Type Persist Host Access Good For
Named Volume App data (db, logs)
Anonymous Volume Ephemeral container data
Bind Mount Local dev, config files
tmpfs Temp data, secrets, cache
Plugin/Remote varies Multi-host or cloud storage

Final Tip

To inspect volumes:

docker volume ls
docker volume inspect <volume_name>
Enter fullscreen mode Exit fullscreen mode

To clean up unused:

docker volume prune
Enter fullscreen mode Exit fullscreen mode

git-lrc
*AI agents write code fast. They also silently remove logic, change behavior, and introduce bugs -- without telling you. You often find out in production.

git-lrc fixes this. It hooks into git commit and reviews every diff before it lands. 60-second setup. Completely free.*

Any feedback or contributors are welcome! It's online, source-available, and ready for anyone to use.

⭐ Star it on GitHub:

GitHub logo HexmosTech / git-lrc

Free, Unlimited AI Code Reviews That Run on Commit

git-lrc logo

git-lrc

Free, Unlimited AI Code Reviews That Run on Commit


git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt

AI agents write code fast. They also silently remove logic, change behavior, and introduce bugs -- without telling you. You often find out in production.

git-lrc fixes this. It hooks into git commit and reviews every diff before it lands. 60-second setup. Completely free.

See It In Action

See git-lrc catch serious security issues such as leaked credentials, expensive cloud operations, and sensitive material in log statements

git-lrc-intro-60s.mp4

Why

  • 🤖 AI agents silently break things. Code removed. Logic changed. Edge cases gone. You won't notice until production.
  • 🔍 Catch it before it ships. AI-powered inline comments show you exactly what changed and what looks wrong.
  • 🔁 Build a habit, ship better code. Regular review → fewer bugs → more robust code → better results in your team.
  • 🔗 Why git? Git is universal. Every editor, every IDE, every AI…




Top comments (0)