在Docker中實現MySQL的災難恢復可以采取以下步驟:
docker run -d --name mysql-container -e MYSQL_ROOT_PASSWORD=password mysql
docker exec mysql-container mysqldump -u root -p --all-databases > /path/to/backup.sql
docker volume create mysql-data
docker run -d --name mysql-container -e MYSQL_ROOT_PASSWORD=password -v mysql-data:/var/lib/mysql mysql
docker cp /path/to/backup.sql mysql-container:/var/lib/mysql/backup.sql
docker stop mysql-container
docker rm mysql-container
docker run -d --name new-mysql-container -e MYSQL_ROOT_PASSWORD=password -v mysql-data:/var/lib/mysql mysql
docker exec new-mysql-container mysql -u root -p < /var/lib/mysql/backup.sql
通過以上步驟,可以在Docker中實現MySQL的災難恢復,保證數據庫在發生災難時能夠及時恢復。