MySQL image ignores bulk configuration docker-compose.yml

Using the official MySQL Docker image, I donโ€™t understand how to mount the data directory to a specific point on the host. Dockerfile Image Sets

VOLUME /var/lib/mysql 

therefore, database data must be stored "somewhere" on the host. I want to be more specific in my docker creation file, so I tried the following:

 mysql: image: mysql:5.7 environment: - MYSQL_ROOT_PASSWORD=password - MYSQL_DATABASE=mydb volumes: - ./database/mysql:/var/lib/mysql 

Starting with docker-compose up everything works fine, but the directory. / database / mysql on the host remains empty, while / var / lib / mysql in the container contains data. Is there a problem in my configuration? Or am I misunderstanding how to use volumes?

+5
source share
1 answer

docker-compose will always try to save data volumes so that you don't lose any data in them. If you started from the data volume and then changed to the host, you can still get the amount of data.

To fix this, run docker-compose stop && docker-compose rm -f , which will delete your containers and your data volumes (this will delete any data in your data volumes). On the next docker-compose up you should see it using the host volume.

Edit: Starting with Compose 1.6, you can run docker-compose stop -v instead of the two commands above.

+9
source

Source: https://habr.com/ru/post/1233546/


All Articles