If you are deploying your applications using docker you may have wondered how to manage the backup of production databases. Indeed, traditionally, without docker, you would have made a small script based on mysql_dump in a cron on the host machine. Simple and efficient.
Unfortunately, under Docker, it is recommended not to install anything outside of the containers. So no cron or mysql_dump.
The first idea that comes is to still install these tools on the host and make port 3306 accessible from the host. Unsatisfactory and complicated solution to implement in the event of a Swarm cluster for example and with non-neutral security impacts.
Simplify the backup of your MySQL docker container
This is why we have developed another method to save another docker container using a docker container in a simple and efficient way, whatever the architecture of your cluster and without installing anything on the host.
The solution is to deploy a simple container which will contain the cron and MySQLldump tools and which will back up the server you want.
It could not be easier :
Add the backup image to your docker compose and provides it with some information :
image : mysql
MYSQL_ROOT_PASSWORD : XXX
– /data/volumes/mysql-db :/var/lib/mysql
image : kiwibackup/mysqlbackup
– /data/backup/db :/backup