Self-hosting / Migrating docker-compose application to M1 Mac
Previously, I hosted Plausible◹ on my Linux server. It’s a Google Analytics alternative, that runs as a set of 4 Docker containers, managed with
docker-compose. Which is cool.
The uncool part is, that I’m spending 20 bucks a month for a VPS, just to run a single application. So, I decided that this waste stop today. With this money, I would get an extra 4 cups of coffee.
I also have an M1 Mac mini sitting around at home and does absolutely nothing. So, this gonna be my home server, I’m gonna migrate the Plausible containers into this machine.
Backing up the data from the old host
When running as containers, Plausible stores its data in 3 Docker volumes:
DRIVER VOLUME NAME local plausible_db-data local plausible_event-data local plausible_geoip
To migrate these data volumes, we first need to export them. Since there is no way to export all of them at once, we need to do it individually, I’m gonna write a small script called
backup to make the job easier.
(Well, actually this script was taken from this Gist◹)
VOLUME_NAME=$1 docker run --rm --volume $VOLUME_NAME:/data \ -v $(pwd):/backup alpine \ tar -zcvf /backup/$VOLUME_NAME.tar /data
This script will create a temporary container, mount the
$VOLUME_NAME volume as its data folder, and create a tarball of that data. Now we can create the backup data:
$ ./backup.sh plausible_db-data $ ./backup.sh plausible_event-data $ ./backup.sh plausible_geoip
The output will be 3 files in the current working directory:
Now I can move these files into my Mac machine.
Restoring data in the new host
In my home machine, I created a script called
restore.sh. Which also creates a temporary container, extracts and mounts the tarball as its data volume with the name of
VOLUME_NAME=$1 docker run --rm \ --volume $VOLUME_NAME:/dbdata \ --volume $(pwd):/backup alpine \ tar xvf /backup/$VOLUME_NAME.tar -C /dbdata --strip 1
And restore the data:
$ ./restore.sh plausible_db-data $ ./restore.sh plausible_event-data $ ./restore.sh plausible_geoip
Migrating docker-compose config
With all the data migrated, now I can just copy the same
docker-compose.yml file from my Linux host into my home machine and run it. But there’s a catch.
When running on ARM64 devices like M1 Mac mini, Docker only supports ARM64 images.
For a self-hosted Plausible application, there are 3 containers:
At the time of writing, only
clickhouse-server has an ARM64 image in the new version, so, we need to modify the
docker-compose.yml to use the alternative multi-arch images (until Plausible supports ARM64 officially).
yandex/clickhouse-serverto the new version
Now things should be good.
The last thing is to deal with the dynamic IP of my home internet, there is a lot of dynamic DNS solution, but the most easy way to handle this is to use Cloudflare Tunnel◹.