Migrate Docker DB to Amazon RDS
While Docker Compose is a fast and convenient way to deploy your Tower instance, production deployments should have a robust database solution to minimize the risk of data loss.
Points to consider before migration
-
Target Database
You have options when choosing your new MySQL-compliant database. While the process is mostly the same, some of the commands will be different (example: MariaDB on RDS).
-
How much data must be moved?
The data in your database must be exported from the MySQL container and imported to the new instance. Depending on the amount of data in your database and the amount of remaining EC2 EBS capacity, you may be able to save your data directly onto the instance, or be forced to make use of a service with more capacity (such as S3).
-
Testing
What level of testing is required to determine the data has been properly migrated?
-
Maintenance window
It is much simpler to initiate a migration once all transactions to the database cease than to do so while jobs are still running. Perform the migration at a time when an outage can occur and notify your users in advance.
-
MySQL container volume retention
Seqera highly suggests retaining your original volume until you are 100% satisfied that the migration occurred without error. So long as the volume is kept, you can fall back to the MySQL container and ensure that Kinnate does not lose any of the material generated thus far.
Prerequisite work
Before starting your migration, do the following:
-
Create an RDS MySQL-compliant instance and populate it with a tower user and tower database.
-
Ensure your EC2 instance and database instance's Security Group(s) have been configured to allow MySQL traffic (default: Port 3306).
Steps
These steps assume the following:
- You have sufficient EC2 instance space to store your data without requiring an S3 mounting solution like S3fs.
- You have implemented a full maintenance outage.
-
Connect to to the EC2 instance using SSH and navigate to Tower's docker-compose folder.
-
Shut down Tower:
docker-compose down
-
Mount a new folder into the MySQL container for migration activities:
-
Create a new folder to hold migration artefacts.
mkdir ~/tower_migration
-
Backup the database.
sudo tar -zcvf ~/tower_migration/tower_backup.tar.gz ~/.tower/db/mysql
-
-
Modify the Tower docker-compose.yml:
- Add new volume entry for the db container.
$HOME/tower_migration:/tower_migration
-
Restart Tower to ensure your changes were successful.
docker-compose down
-
Stop all the non-MySQL containers.
docker container stop <CONTAINER ID>
-
Exec onto the MySQL ontainer.
docker exec -it <CONTAINER ID> /bin/bash
-
Dump your data to disk.
mysqldump -u tower -p --databases tower --no-tablespaces --set-gtid-purged=OFF > /tower_migration/tower_dumpfile.sql
-
Exit the container.
-
-
Stop the MySQL container.
docker container stop <CONTAINER ID>
-
Import the dump file into your new RDS instance.
mysql --host <DB-HOST> --port 3306 -u tower -p tower < ~/tower_migration/tower_dumpfile.sql
-
Log on to the RDS instance and ensure that the tower database is populated with tables prefixed by 'tw_'.
-
Modify the tower.env in the Tower docker folder:
- Comment out the existing TOWER_DB-* variables.
- Add new entries relevant to your database choice.
- Save and exit.
-
Restart Tower.
docker-compose up
-
Confirm that Tower starts and that your data is available when you log in.
Congratulations! Your migration is complete and your testing can begin.