Reputation: 2740
I am running two docker containers.
I want to persist my database, therefore I use volumes in my docker-compose file. Still I lose data whenever I restart the containers (docker-compose down and up).
What I am missing? (I am on ubuntu 20.04)
services:
adminer:
image: adminer
restart: always
ports:
- 8080:8080
db:
image: mysql:latest
restart: always
environment:
MYSQL_ROOT_PASSWORD: 'example' # TODO: Change this
volumes:
- "./config/my.conf:/etc/mysql/conf.d/config-file.cnf"
- "./data:/var/lib/mysql:rw"
Upvotes: 1
Views: 3314
Reputation: 1
docker-compose down -v removes the volume associated .create a named volume will solve the problem
volumes:
- my-data-volume:/var/lib/mysql
Upvotes: 0
Reputation: 115
I have the same issue
just remove " (quotation marks) from
- "./data:/var/lib/mysql:rw"
and write it without them.
- ./data:/var/lib/mysql
you can easily run docker-compose down
and your data will be persistent
Upvotes: 0
Reputation: 11806
Use docker-compose stop
instead of docker-compose down
.
From the documentation:
docker-compose down: Stops containers and removes containers, networks, volumes, and images created by up.
Upvotes: 1