webdevops / php-docker-boilerplate

:stew: PHP Docker Boilerplate for Symfony, Wordpress, Joomla or any other PHP Project (NGINX, Apache HTTPd, PHP-FPM, MySQL, Solr, Elasticsearch, Redis, FTP)
https://webdevops.io/projects/php-docker-boilerplate/
MIT License
562 stars 186 forks source link

DB data does not persist #67

Closed timkelty closed 7 years ago

timkelty commented 7 years ago

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?

timkelty commented 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:
mblaschke commented 7 years ago

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?

timkelty commented 7 years ago

Steps to reproduce:

mblaschke commented 7 years ago

"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 :)

timkelty commented 7 years ago

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.

timkelty commented 7 years ago

👍