I've setup a basic MariaDB instance running in Docker - basically from starting the container using the Kitematic UI, changing the settings, and letting it run.
Today, I wanted to make a backup, so I used Kitematic to change the port so I could access it from a machine to make automated backups. After changing the port in Kitematic, it seems to have started a fresh MariaDB container (i.e. all my data seems to be removed).
Is that the expected behavior? And, more importantly, is there any way to recover the seemingly missing data, or has it been completely removed?
Also, if the data is actually removed, what is the preferred way to change settings—such as the exposed ports—without losing all changes? docker commit
?
Notes:
docker -ps a
shows the database status as "Up for X minutes" when the original had been up for several daysThanks in advance!
UPDATE:
It looks like the recommended procedure to retain data (without creating a volume or similar) is to:
docker commit <containerid> <name/tag>
)...taken from this answer.
Yes, this is expected behavior. If you want your data to be persistant you should mount volume from host (via --volume
option for docker run
) or from another container and store your database files at this volume.
docker run --volume /path/on/your/host/machine:/var/lib/mysql mariadb
Losing changes are actually core feature of containers so it can not be omitted. This way you can be sure that between every docker run
you get fresh environment without any changes. If you want your changes to be permanent you should do them in your image's Dockerfile
, not in container itself.
For more information please visit official documentation: https://docs.docker.com/engine/tutorials/dockervolumes/.