Closed timkelty closed 7 years ago
Adding a mysql volume remedied this, but are you intending for people to use the storage container for this?
version: '2'
services:
mysql:
build:
context: docker/mysql/
dockerfile: MySQL-5.7.Dockerfile
ports:
- 13306:3306
volumes:
- mysql:/var/lib/mysql
env_file:
- etc/environment.yml
- etc/environment.development.yml
volumes:
mysql:
There is already a volume set inside the Dockerfile for MySQL 8.0: https://github.com/docker-library/mysql/blob/86431f073b3d2f963d21e33cb8943f0bdcdf143d/8.0/Dockerfile#L62
also for MySQL 5.7: https://github.com/docker-library/mysql/blob/86431f073b3d2f963d21e33cb8943f0bdcdf143d/5.7/Dockerfile#L68
and MySQL 5.6: https://github.com/docker-library/mysql/blob/86431f073b3d2f963d21e33cb8943f0bdcdf143d/5.6/Dockerfile#L62
But you will lose the data if you remove the container and the volume. Please don't use a storage container, use the volume or a host mounted volume :)
Any steps how to reproduce the lost data? Which docker solution are you using?
Steps to reproduce:
docker-compose.yml
(so MySQL-5.6.Dockerfile)docker-compose up -d
database
database that has been createddocker-compose down
docker-compose up -d
database
has no tables :("Works as intended"
From the documentation of docker-compose down
:
Stops containers and removes containers, networks, volumes, and images created by up.
By default, the only things removed are:
- Containers for services defined in the Compose file
- Networks defined in the networks section of the Compose file
- The default network, if one is used
Networks and volumes defined as external are never removed.
https://docs.docker.com/compose/reference/down/
What you want to use is docker-compose stop
:)
Update: Ah, sorry.. then we have to specify the volume as external.. so this change makes sense :)
Ah ok - thanks for the clarification.
I always use down
so I don't have unused containers all over my system.
So I guess what I'm doing would be way to persist that data. I might argue the example compose files should have that too.
FWIW I'm coming from using https://github.com/laradock/laradock, which has a mysql volume and will therefore persist between up
and down
.
👍
When I bring a container down, I lose my data. Surely this isn't expected?
Don't we need a volume for
/var/lib/mysql
?