A
A
Artem Gribkov2016-10-19 00:38:13
MySQL
Artem Gribkov, 2016-10-19 00:38:13

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

3 answer(s)
A
Anton Shvets, 2016-10-19
@L1Qu0R

-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.

M
Max, 2016-10-19
@zenwalker

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

https://docs.docker.com/engine/tutorials/dockervolumes/

L
lega, 2016-10-19
@lega

Do you constantly dump at the end of the work and fill it at the start?

Do not delete the container, then the data will not be lost, and you can mount sorts into the application container, and "update" without restarting.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question