S
S
Sta_sko2021-03-10 22:28:05
Docker
Sta_sko, 2021-03-10 22:28:05

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

3 answer(s)
D
Dmitry, 2021-03-10
@q2digger

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/

Now, when you start your project, when the base takes off, the container will automatically try to upload a dump to the base, which it will find in its folder / docker-entrypoint-initdb.d/
Then wordpress will simply detect the already filled base ..

D
Dmitry Shitskov, 2021-03-10
@Zarom

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.

R
Ruslan, 2021-03-16
@Tiasar

You can put sql scripts with dumps in the docker-entrypoint-initdb.d folder
At the first init of the container, they will be executed and there will be a structure and data that you need

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question