The setup I describe above stores data inside of the container. This data is lost when the container is deleted (docker-compose down)
docker-compose down
You could mount a volume so the data is persisted on your local machine.
Looking at hub.docker.com/_/mysql/ (search for Where to Store Data), we can update the docker-compose.yml with another volume mount as follows:
docker-compose.yml
# ./docker-compose.yml version: '3' services: db: image: mysql:5.7 environment: MYSQL_ROOT_PASSWORD: my_secret_pw_shh MYSQL_DATABASE: test_db MYSQL_USER: devuser MYSQL_PASSWORD: devpass volumes: - ./sql:/var/lib/mysql ports: - "9906:3306" web: image: php:7.2.2-apache container_name: php_web depends_on: - db volumes: - ./php/:/var/www/html/ ports: - "8100:80" stdin_open: true tty: true
Now data will persist in the ./sql directory.
./sql
Thank you very much!
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
The setup I describe above stores data inside of the container. This data is lost when the container is deleted (
docker-compose down
)You could mount a volume so the data is persisted on your local machine.
Looking at hub.docker.com/_/mysql/ (search for Where to Store Data), we can update the
docker-compose.yml
with another volume mount as follows:Now data will persist in the
./sql
directory.Thank you very much!