I revisted this problem, and got it working using the linuxserver.io image, instead of the one I was trying last year. The linuxserver.io documentation is a little vague on the steps to get Mastodon running. You need to generate your secrets to add to your docker-compose.yml or secrets file BEFORE spinning up the container:
docker run --rm -it --entrypoint /bin/bash lscr.io/linuxserver/mastodon generate-secret SECRET_KEY_BASE
docker run --rm -it --entrypoint /bin/bash lscr.io/linuxserver/mastodon generate-secret OTP_SECRET
The third command generates both the VAPID_PRIVATE_KEY and VAPID_PUBLIC_KEY
docker run --rm -it --entrypoint /bin/bash lscr.io/linuxserver/mastodon generate-vapid
After you have generated the secrets, add them to your docker-compose.yml file (also editing your smtp, database information, etc), and run the container.
mastodon:
image: lscr.io/linuxserver/mastodon:latest
container_name: mastodon
environment:
- PUID=1000
- PGID=1000
- TZ=America/Chicago
- LOCAL_DOMAIN=mastodon.mydomain.com #<--- Change this to where you are hosting mastodon
- REDIS_HOST=mastodon_redis
- REDIS_PORT=6379
- DB_HOST=mastodon_db
- DB_USER=mastodon
- DB_NAME=mastodon
- DB_PASS=mastodon_password
- DB_PORT=5432
- ES_ENABLED=false
- SECRET_KEY_BASE= #<-- Previously generated secret
- OTP_SECRET= #<-- Previously generated secret
- VAPID_PRIVATE_KEY= #<-- Previously generated key
- VAPID_PUBLIC_KEY= #<-- Previously generated key
- SMTP_SERVER=smtp.server.com #<-- Change to your smtp
- SMTP_PORT=465
- SMTP_LOGIN=mastodon_notifications@mydomain.com
- SMTP_PASSWORD=<password for user at SMTP_LOGIN>
- SMTP_FROM_ADDRESS=mastodon_notifications@mydomain.com
- SMTP_AUTH_METHOD=plain
- SMTP_SSL=true
- SMTP_ENABLE_STARTTLS_AUTO=true
- SMTP_OPENSSL_VERIFY_MODE=none
- SMTP_DELIVERY_METHOD=smtp
- SMTP_DOMAIN=localhost
- S3_ENABLED=false
- WEB_DOMAIN=mastodon.mydomain.com #optional
- SIDEKIQ_ONLY=false #optional
- SIDEKIQ_DEFAULT=false #optional
- SIDEKIQ_THREADS=5 #optional
- DB_POOL=5 #optional
volumes:
- ./config:/config
ports:
- 80:80
- 443:443
restart: unless-stopped
networks:
mastodon_net:
PROXY_NET:
db:
image: postgres:14
container_name: mastodon_db
networks:
- local
volumes:
- ./postgres/data:/var/lib/postgresql/data
environment:
- POSTGRES_DB=mastodon
- POSTGRES_USER=mastodon
- POSTGRES_PASSWORD=mastodon_password
- 'POSTGRES_HOST_AUTH_METHOD=trust'
healthcheck:
test: ['CMD', 'pg_isready', '-U', 'postgres']
restart: unless-stopped
networks:
mastodon_net:
redis:
image: redis:latest
container_name: mastodon_redis
command: redis-server --appendonly yes --appendfsync everysec
volumes:
- ./redisconfig/data:/data
ulimits:
nofile:
soft: 65536
hard: 65536
healthcheck:
test: ['CMD', 'redis-cli', 'ping']
restart: unless-stopped
networks:
mastodon_net:
networks:
mastodon_net:
internal: true
PROXY_NET:
external: true
name: PROXY_NET_network
The first run will take a LONG time to build the app and the database. I let it run, and checked the log periodically to confirm when it was finished.
Here are some references that helped me fill in the gaps:
https://www.reddit.com/r/selfhosted/comments/yv9296/easiest_allinone_docker_compose_to_deploy_mastodon/
https://www.bentasker.co.uk/posts/blog/general/running-mastodon-in-docker-compose.html