This is a rewriting of the official Funkwhale multi-container installation.
The official docker-compose works, but is written in some very questionable way; creating serious issues in security, portability, modularity, readability and maintenability of the entire stack. The installation is also not automated, but requires extra steps (excluding configuration that doesn't count) to initialize for the first time the instance.
There has been a lot of changes, I will list the most notable ones:
- Before: (see the appendix)
- the containers were all under the same network which gave them internet access;
- the
apiandnginx(the reverse-proxy) services were exposing to the public (using theportdirective), respectively the5000/tcpand80/tcpports; - the ports of
postgresandrediswere not documented (noexposedirective used).
- Now: (see the appendix)
- There are three distinct networks with precise purposes:
- An internal network (no Internet access) containing all the services;
- A network with Internet access with only the services that really need it, namely:
apiandceleryworker; - An optional external network to hook the
nginxservice only (in case you have a main reverse-proxy on your server).
- the
apiandnginx(the reverse-proxy) services no longer expose their ports to the public, they are only documented with theexposedirective; - the ports of
postgresandredisservices are now documented with theexposedirective.
- There are three distinct networks with precise purposes:
Info: read this and this on the official Docker docs to understand the difference between
.envfile and env files imported withenv_file.
- Before:
- All the environment variables for all services were mixed together inside the same
*.envfile (.env); - The
.envfile (which is automatically loaded by Docker Compose to be used within the.ymlfile), is also directly injected in all serivices with theenv_filedirective, exposing information to services that doesn't (and shouldn't) need it.
- All the environment variables for all services were mixed together inside the same
- Now:
- The environment variables are now separated in different files depending on the service or set of services that does need them; the
.envfile now has only variables concerning the configuration at the stack level, not service, except for theFUNKWHALE_HOSTNAMEvariable which is passed inside the containers via theenvironmentdirective. - The
env_fileis now used only when needed and import*.envfiles containing variables only needed for the target service.
- The environment variables are now separated in different files depending on the service or set of services that does need them; the
- Configurable paths for the volumes mounting point inside the containers has been removed, it's something that has no sense to exist and unnecessarily complicate things.
- Has been added the possibility to configure the
restartandcontainer_namedirective on all the containers. - Has been added the possibility to configure the tag on all services and image on some (
nginx,postgres,redis). - In the
funkwhale.templatehas been removed all the unnecessary variables and replaced with static paths which reflects the static volume mountpoints I set for the service. - The
funkwhale_proxy.confandfunkwhale.templatehas been moved to a dedicated subfolder callednginx. - In case the system administrator has intention to hook the
nginxservice to the network of its main reverse-proxy which happens to have a companion (for example docker-gen) I've set some variables with dummy values already in thenginx.envfile. - The directives in the
docker-compose.ymlfile now are no longer sorted randomly; the order is the same for all and follows a criteria that (arguably) makes more sense. - Except for
DJANGO_SECRET_KEYandFUNKWHALE_HOSTNAMEwhich are mandatory variables to manually set, all the optional variables are left empty in the*.varfiles by default and has a correspondent default value defined in thedocker-compose.ymlfile (except forfunkwhale.env). postgresservice image tag has been upgraded from11to12.4andredisfrom to5to6.
- The overall stack structure remained the same, with the same container images.
- The name of the services (but they should be changed to a more generic ones,
like:
web,api,db,cache, etc...). - The extra manual steps necessary to initialize for the first time the app
- The extra manual steps necessary to partially initialize the database in case to upgrade to a new version (tables or columns has been added/removed)
- The extra manual steps in case of bump to a new version of the service that is not backward compatible (for example posgres likes to break compatibility at every major release).
These are the minimum number of variables you need to set in order to get the whole stack working.
- Remove the
.exampleextension from all files (or copy new ones without it) - Set the
DJANGO_SECRET_KEYvariable infunkwhale.env - Set the
FUNKWHALE_HOSTNAMEvariable in.env - (only if using a reverse proxy with docker-companion) set the dedicated variables in
nginx.env
Initialize the database:
docker-compose run --rm api python manage.py migrateCreate the superuser of the instance:
docker-compose run --rm api python manage.py createsuperuserLaunch the whole stack:
docker-compose build --pull && docker-compose up -d
