Answer the question
In order to leave comments, you need to log in
How to create your own disk image with the database already mounted?
Good afternoon!
Essence of the question: I am mastering Docker, I want to get a ready-made image with Wordpress preinstalled. Docker Hub offers a solution in the form of a Wordpress image, which in turn uses Wordpress and Mysql:5.7 (currently) images.
When creating a container from this image, we are first offered to create a Wordpress user (the empty database for the site itself has already been created), then Wordpress already fills the database with its tables. And I want the database to be already filled when the container is launched and it remains only to log in to the site.
If you use Docker Volume, forwarding from the host to the container, then changing the container changes the content on the host. (when used for example in docker-compose.yml syntax volumes: /home/site/db:/var/lib/mysql).
How to flash the image with your database so that changes in the container do not change the content on the host?
Answer the question
In order to leave comments, you need to log in
First you need to have "your" database dump. Ok, let's assume you have it.
Now go to the folder where you have docker-compose.yml , make a directory there, for example dump, and upload your database dump to it.
then you write this folder in the description of the mysql container, mount it like this:
volumes :
- ./dump/:/docker-entrypoint-initdb.d/
Probably the easiest option:
Do not skip volume.
Run the standard WordPress comp with the base, carry out all the necessary initialization. Then stop the container with the database and docker commit to the new image. Next, use this new database image in docker compose.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question