- Migrate MySQL database
- Migrate Redmine application
Create an archive from the source data directory, where data to be migrated:
/var/lib/mysql is the default location where all database related data are stored.
Download the archive:
Extract to the directory where we will map the host volume to the guest:
Download the latest (
5.7.16 make sure it is the latest, because
8.x branch might not work) MySQL Docker image:
Run a MySQL container with the data directory mounted from the host:
Environment variables (
MYSQL_PASSWORD) become unnecessary:
Do note that none of the variables below will have any effect if you start the container with a data directory that already contains a database: any pre-existing database will always be left untouched on container startup.[^1]
Now I should be able to access my existing database:
But when accessing MySQL database from another host, we have to update the permissions. Let’s log into MySQL with
Issue SQL commands:
localhost is allowed for both the database and the user. This is problematic. How does one know the host of the container yet to be created? The easiest way is to allow access from all hosts:
We can restrict to a set of IP addresses such as
172.17.0.% or sub domains
%.example.com. Docker networking uses
The better way is that when linking containers, should be able to update
/etc/hosts file to include a
redmine container field. Then, a wild card is not necessary.
But having to allow all hosts to connect is fine, because all hosts do not mean all hosts. The port is not bind or map to any open port in the host machine. Only the host (
172.17.0.1) and other Docker containers inside the host can discover the service provided. Other machines or containers outside the host is not able to access at all.
Restart the container to have the update taking effect:
For a basic Redmine setup, there aren’t much to migrate, mainly just three directories,
log, others are application data. Configuration could be done via environment variables, and if logs weren’t important to migrate, we just need to move the
files directory, which is used for file upload.