Answer the question
In order to leave comments, you need to log in
What is the best way to save the state of the database in docker?
How to save the state of the database in feng shui when developing locally?
I have two images running, the first is, for example, mysql, and the second is already a web server + the application itself.
So here's how not to lose the state of the database, constantly dump at shutdown and upload at startup? Or, at startup, mount the entire database: -v /mysql:/var/lib/mysql ?
Get on the right path
Answer the question
In order to leave comments, you need to log in
-v /mysql:/var/lib/mysql is quite feng shui
I do something like this:
- in the db container -v ./mysql:/var/lib/mysql
- in the web server container -v ./www: /var/www/html
- if it is necessary to build my own images, I keep docker files and the data they need in the build folder.
And in the same folder with the project, I have a folder with a database, a folder with scripts / sources and other file data, and a folder with images.
Everything neatly lies side by side, is launched and extinguished through docker-compose in one complex.
I didn’t understand the point of making named docker volumes, the same thing, it will only be in the /var/lib/docker folder. The only reason is if the data volume is used by several containers at once, and you can immediately understand what it is by name.
Option 1:
Mount a directory from the host machine into the container (i.e. as you said: -v /mysql:/var/lib/mysql ).
Create a volume and mount it into a container.
$ docker volume create --name mysql_data
$ docker run -v mysql_data:/var/lib/mysql mysql
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question