What Are Volumes?

A mechanism for saving Docker container data to the host machine. Data persists even after the container is deleted.

docker run -d -v mydata:/var/lib/mysql mysql:8

Configuration in docker-compose

services:
  db:
    image: mysql:8
    volumes:
      - db_data:/var/lib/mysql

volumes:
  db_data:

Volume Commands

docker volume ls
docker volume create mydata
docker volume rm mydata
docker volume prune

Key Points

  • docker compose down -v also deletes volumes — be careful
  • Deleting a container without a volume wipes all its data

For docker-compose setups that use volumes, see How to Use docker-compose for a complete overview.

Looking for reliable cloud infrastructure? Check out these developer-friendly services.