/data/service/mysql_backup/docker-compose.yml
文件內容mysql
version: "2" services: mysql_backup: image: xxfaxy/self-alpine-mysql-backup container_name: mysql_backup environment: - READ_DATABASE_HOST=主機 - READ_DATABASE_PORT=端口 - READ_DATABASE_NAME=數據庫名稱 - READ_DATABASE_USERNAME=用戶名 - READ_DATABASE_PASSWORD=密碼 volumes: - /home/test/mysql_backup:/data/mysql restart: always
/data/service/mysql_backup/remote.sh
文件內容git
#!/bin/bash echo 'please select:' echo '1.docker images -a' echo '2.docker ps -a' echo '3.docker rm -f @container' echo '4.docker rmi -f @image' echo '5.docker pull @image' echo '6.docker-compose up -d' echo '7.docker exec -it @container sh' image=xxfaxy/self-alpine-mysql-backup container=mysql_backup count=$# if [ $count -gt 0 ] then name=$1 else read name fi case $name in '1') sudo docker images -a ;; '2') sudo docker ps -a ;; '3') sudo docker rm -f $container ;; '4') #sudo docker rmi -f $image ;; '5') sudo docker pull $image ;; '6') sudo docker-compose --file=/data/service/mysql_backup/docker-compose.yml up -d ;; '7') sudo docker exec -it $container sh ;; *) echo "not find" ;; esac
xxfaxy/self-alpine-mysql-backup
鏡像大小爲56.77 MB
github
你也能夠本身製做鏡像,決定備份的細節,下面是源碼sql
https://github.com/xxfaxy/mysql_backupdocker
個人首發博客數據庫