Mastodon (stack)
Mastodon is a free, open-source social network server based on ActivityPub where users can follow friends and discover new ones..
Configuration
TypeComposelinuxlscr.io/linuxserver/mastodon:latest80:80443:443/config : /portainer/Files/AppData/Config/mastodonPUID=1000PGID=1000TZ=Europe/AthensLOCAL_DOMAIN=example.comREDIS_HOST=redisREDIS_PORT=6379DB_HOST=dbDB_USER=mastodonDB_NAME=mastodonDB_PASS=mastodonDB_PORT=5432ES_ENABLED=falseSECRET_KEY_BASE=OTP_SECRET=VAPID_PRIVATE_KEY=VAPID_PUBLIC_KEY=SMTP_SERVER=mail.example.comSMTP_PORT=25SMTP_LOGIN=SMTP_PASSWORD=[email protected]S3_ENABLED=falseWEB_DOMAIN=mastodon.example.comES_HOST=esES_PORT=9200ES_USER=elasticES_PASS=elasticS3_BUCKET=AWS_ACCESS_KEY_ID=AWS_SECRET_ACCESS_KEY=S3_ALIAS_HOST=SIDEKIQ_ONLY=falseSIDEKIQ_QUEUE=SIDEKIQ_DEFAULT=falseSIDEKIQ_THREADS=5DB_POOL=5unless-stoppedInstallation
- Ensure both Docker and Portainer are installed, and up-to-date
- Log into your Portainer web UI
- Under Settings → App Templates, paste the below URL
- Head to Home → App Templates, and the list of apps will show up
- Select the app you wish to deploy, fill in any config options, and hit Deploy
Template Import URL
https://raw.githubusercontent.com/Lissy93/portainer-templates/main/templates.json
Show Me
docker run -d --name mastodon \
-p 80:80 \
-p 443:443 \
-e 'PUID=1000' \
-e 'PGID=1000' \
-e 'TZ=Europe/Athens' \
-e 'LOCAL_DOMAIN=example.com' \
-e 'REDIS_HOST=redis' \
-e 'REDIS_PORT=6379' \
-e 'DB_HOST=db' \
-e 'DB_USER=mastodon' \
-e 'DB_NAME=mastodon' \
-e 'DB_PASS=mastodon' \
-e 'DB_PORT=5432' \
-e 'ES_ENABLED=false' \
-e 'SECRET_KEY_BASE=' \
-e 'OTP_SECRET=' \
-e 'VAPID_PRIVATE_KEY=' \
-e 'VAPID_PUBLIC_KEY=' \
-e 'SMTP_SERVER=mail.example.com' \
-e 'SMTP_PORT=25' \
-e 'SMTP_LOGIN=' \
-e 'SMTP_PASSWORD=' \
-e '[email protected]' \
-e 'S3_ENABLED=false' \
-e 'WEB_DOMAIN=mastodon.example.com' \
-e 'ES_HOST=es' \
-e 'ES_PORT=9200' \
-e 'ES_USER=elastic' \
-e 'ES_PASS=elastic' \
-e 'S3_BUCKET=' \
-e 'AWS_ACCESS_KEY_ID=' \
-e 'AWS_SECRET_ACCESS_KEY=' \
-e 'S3_ALIAS_HOST=' \
-e 'SIDEKIQ_ONLY=false' \
-e 'SIDEKIQ_QUEUE=' \
-e 'SIDEKIQ_DEFAULT=false' \
-e 'SIDEKIQ_THREADS=5' \
-e 'DB_POOL=5' \
-v /portainer/Files/AppData/Config/mastodon:/config \
--restart=unless-stopped \
lscr.io/linuxserver/mastodon:latestIf the stack expects env vars, set them or add them to a .env file first.
services:
mastodon:
image: lscr.io/linuxserver/mastodon:latest
container_name: mastodon
environment:
- PUID=1000
- PGID=1000
- TZ=Europe/Athens
- LOCAL_DOMAIN=example.com
- REDIS_HOST=redis
- REDIS_PORT=6379
- DB_HOST=db
- DB_USER=mastodon
- DB_NAME=mastodon
- DB_PASS=mastodon
- DB_PORT=5432
- ES_ENABLED=false
- SECRET_KEY_BASE=
- OTP_SECRET=
- VAPID_PRIVATE_KEY=
- VAPID_PUBLIC_KEY=
- SMTP_SERVER=mail.example.com
- SMTP_PORT=25
- SMTP_LOGIN=
- SMTP_PASSWORD=
- [email protected]
- S3_ENABLED=false
- WEB_DOMAIN=mastodon.example.com #optional
- ES_HOST=es #optional
- ES_PORT=9200 #optional
- ES_USER=elastic #optional
- ES_PASS=elastic #optional
- S3_BUCKET= #optional
- AWS_ACCESS_KEY_ID= #optional
- AWS_SECRET_ACCESS_KEY= #optional
- S3_ALIAS_HOST= #optional
- SIDEKIQ_ONLY=false #optional
- SIDEKIQ_QUEUE= #optional
- SIDEKIQ_DEFAULT=false #optional
- SIDEKIQ_THREADS=5 #optional
- DB_POOL=5 #optional
volumes:
- /portainer/Files/AppData/Config/mastodon:/config
ports:
- 80:80
- 443:443
restart: unless-stopped
Or, use the original compose file, straight from the template repo. Deploy with:
git clone https://github.com/xneo1/portainer_templates
cd portainer_templates
docker compose -f Template/Stack/mastodon.yml up -dSave this file as mastodon-stack-stack.yml, then from a manager node, run docker stack deploy -c mastodon-stack-stack.yml mastodon-stack
version: '3.8'
services:
mastodon-stack:
image: lscr.io/linuxserver/mastodon:latest
ports:
- '80:80'
- '443:443'
volumes:
- /portainer/Files/AppData/Config/mastodon:/config
environment:
PUID: '1000'
PGID: '1000'
TZ: Europe/Athens
LOCAL_DOMAIN: example.com
REDIS_HOST: redis
REDIS_PORT: '6379'
DB_HOST: db
DB_USER: mastodon
DB_NAME: mastodon
DB_PASS: mastodon
DB_PORT: '5432'
ES_ENABLED: 'false'
SECRET_KEY_BASE: ''
OTP_SECRET: ''
VAPID_PRIVATE_KEY: ''
VAPID_PUBLIC_KEY: ''
SMTP_SERVER: mail.example.com
SMTP_PORT: '25'
SMTP_LOGIN: ''
SMTP_PASSWORD: ''
SMTP_FROM_ADDRESS: [email protected]
S3_ENABLED: 'false'
WEB_DOMAIN: mastodon.example.com
ES_HOST: es
ES_PORT: '9200'
ES_USER: elastic
ES_PASS: elastic
S3_BUCKET: ''
AWS_ACCESS_KEY_ID: ''
AWS_SECRET_ACCESS_KEY: ''
S3_ALIAS_HOST: ''
SIDEKIQ_ONLY: 'false'
SIDEKIQ_QUEUE: ''
SIDEKIQ_DEFAULT: 'false'
SIDEKIQ_THREADS: '5'
DB_POOL: '5'
deploy:
restart_policy:
condition: any
Save each file below into a folder, then run kubectl apply -f .
Written for k3s, but works on any cluster: bind mounts use hostPath, named volumes get a
persistent volume claim, and ports are exposed via a LoadBalancer service.
mastodon-stack-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: mastodon-stack
labels:
app: mastodon-stack
spec:
replicas: 1
selector:
matchLabels:
app: mastodon-stack
template:
metadata:
labels:
app: mastodon-stack
spec:
containers:
- name: mastodon-stack
image: lscr.io/linuxserver/mastodon:latest
env:
- name: PUID
value: '1000'
- name: PGID
value: '1000'
- name: TZ
value: Europe/Athens
- name: LOCAL_DOMAIN
value: example.com
- name: REDIS_HOST
value: redis
- name: REDIS_PORT
value: '6379'
- name: DB_HOST
value: db
- name: DB_USER
value: mastodon
- name: DB_NAME
value: mastodon
- name: DB_PASS
value: mastodon
- name: DB_PORT
value: '5432'
- name: ES_ENABLED
value: 'false'
- name: SECRET_KEY_BASE
value: ''
- name: OTP_SECRET
value: ''
- name: VAPID_PRIVATE_KEY
value: ''
- name: VAPID_PUBLIC_KEY
value: ''
- name: SMTP_SERVER
value: mail.example.com
- name: SMTP_PORT
value: '25'
- name: SMTP_LOGIN
value: ''
- name: SMTP_PASSWORD
value: ''
- name: SMTP_FROM_ADDRESS
value: [email protected]
- name: S3_ENABLED
value: 'false'
- name: WEB_DOMAIN
value: mastodon.example.com
- name: ES_HOST
value: es
- name: ES_PORT
value: '9200'
- name: ES_USER
value: elastic
- name: ES_PASS
value: elastic
- name: S3_BUCKET
value: ''
- name: AWS_ACCESS_KEY_ID
value: ''
- name: AWS_SECRET_ACCESS_KEY
value: ''
- name: S3_ALIAS_HOST
value: ''
- name: SIDEKIQ_ONLY
value: 'false'
- name: SIDEKIQ_QUEUE
value: ''
- name: SIDEKIQ_DEFAULT
value: 'false'
- name: SIDEKIQ_THREADS
value: '5'
- name: DB_POOL
value: '5'
ports:
- containerPort: 80
protocol: TCP
- containerPort: 443
protocol: TCP
volumeMounts:
- name: mastodon-stack-data-0
mountPath: /config
volumes:
- name: mastodon-stack-data-0
hostPath:
path: /portainer/Files/AppData/Config/mastodon
mastodon-stack-service.yaml
apiVersion: v1
kind: Service
metadata:
name: mastodon-stack
spec:
type: LoadBalancer
selector:
app: mastodon-stack
ports:
- name: 80-tcp
port: 80
targetPort: 80
protocol: TCP
- name: 443-tcp
port: 443
targetPort: 443
protocol: TCP
Save this file as ~/.config/containers/systemd/mastodon-stack.container
[Unit]
Description=Mastodon (stack)
[Container]
Image=lscr.io/linuxserver/mastodon:latest
ContainerName=mastodon-stack
PublishPort=80:80
PublishPort=443:443
Environment=PUID=1000
Environment=PGID=1000
Environment=TZ=Europe/Athens
Environment=LOCAL_DOMAIN=example.com
Environment=REDIS_HOST=redis
Environment=REDIS_PORT=6379
Environment=DB_HOST=db
Environment=DB_USER=mastodon
Environment=DB_NAME=mastodon
Environment=DB_PASS=mastodon
Environment=DB_PORT=5432
Environment=ES_ENABLED=false
Environment=SECRET_KEY_BASE=
Environment=OTP_SECRET=
Environment=VAPID_PRIVATE_KEY=
Environment=VAPID_PUBLIC_KEY=
Environment=SMTP_SERVER=mail.example.com
Environment=SMTP_PORT=25
Environment=SMTP_LOGIN=
Environment=SMTP_PASSWORD=
Environment[email protected]
Environment=S3_ENABLED=false
Environment=WEB_DOMAIN=mastodon.example.com
Environment=ES_HOST=es
Environment=ES_PORT=9200
Environment=ES_USER=elastic
Environment=ES_PASS=elastic
Environment=S3_BUCKET=
Environment=AWS_ACCESS_KEY_ID=
Environment=AWS_SECRET_ACCESS_KEY=
Environment=S3_ALIAS_HOST=
Environment=SIDEKIQ_ONLY=false
Environment=SIDEKIQ_QUEUE=
Environment=SIDEKIQ_DEFAULT=false
Environment=SIDEKIQ_THREADS=5
Environment=DB_POOL=5
Volume=/portainer/Files/AppData/Config/mastodon:/config
[Service]
Restart=always
[Install]
WantedBy=default.targetThen reload systemd and start the service:
systemctl --user daemon-reload
systemctl --user start mastodon-stackFor a system-wide service, use /etc/containers/systemd/ and drop --user.
For more installation options, see the Documentation in our GitHub repo
Serve Mastodon (stack) on your own domain behind Caddy, Nginx or Traefik. Fill in your domain and copy the result. It's a starting point, some apps need their own base URL or extra headers set too.
Proxying mastodon-stack.example.com to http://mastodon:80
Add this to your Caddyfile
mastodon-stack.example.com {
reverse_proxy http://mastodon:80
}Check the logs first
Nine times out of ten the logs tell you exactly what went wrong.
- In Portainer, go to Containers, click the container, then Logs. Or run
docker logs <container> - Exit codes help too:
137means killed, usually out of memory.126or127means the command inside the image is broken.
Port already in use
If deployment fails with "Bind for 0.0.0.0:80 failed: port is already allocated", something else on your server is using that port.
- Find what's using it:
sudo ss -tlnp | grep :80 - Stop the other service, or pick a different host port. In
80:80only the left number is yours to change, the right one belongs to the app.
Running but the page won't load
The container is up but nothing appears in your browser.
- Use your server's real IP:
http://your-server-ip:80. The 0.0.0.0 link Portainer shows isn't a real address. - Give it a minute after first deploy, mastodon can take a while to initialise.
- Make sure your firewall allows the port, e.g.
sudo ufw allow 80
Permission denied on volumes
If the logs show "permission denied", the app can't write to its data folder on the host.
- Fix the ownership:
sudo chown -R 1000:1000 /portainer/Files/AppData/Config/mastodon - Or set the
PUIDandPGIDvariables (defaults 1000:1000) to match your own user, found withid $USER
Image won't pull
Test the pull directly on the host: docker pull lscr.io/linuxserver/mastodon:latest
- "manifest unknown" means the tag no longer exists. This template uses
latest, so try pinning a specific version instead. - "toomanyrequests" is the Docker Hub rate limit. Log in with
docker loginto raise it. - "no space left on device" means a full disk. Reclaim space with
docker system prune
"exec format error"
This means the image was built for a different CPU architecture than your server.
- Check yours with
uname -m: x86_64 is amd64, aarch64 is arm64. Raspberry Pi and other ARM boards are the usual culprits.
Container keeps restarting
The unless-stopped restart policy relaunches the app after every crash, so the real error can scroll past.
- Check the logs right after a restart, the last few lines before it died are the useful ones.
- Get the exit code with
docker inspect <container> --format '{{.State.ExitCode}}' - Still stuck? Redeploy once with the restart policy set to
noso the failure stays visible.
Required settings are blank
SECRET_KEY_BASE, OTP_SECRET, VAPID_PRIVATE_KEY, VAPID_PUBLIC_KEY, SMTP_LOGIN, SMTP_PASSWORD, S3_BUCKET, AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, S3_ALIAS_HOST, SIDEKIQ_QUEUE have no default value, and mastodon may crash or misbehave if left empty.
- Fill them in on the deploy screen before hitting deploy.
Stack won't deploy
Compose stacks fail fast on small mistakes, and Portainer shows the reason just above the editor.
- YAML only accepts spaces for indentation, a single tab breaks the whole file.
Raise an issue
Found something which isn't working as it should? Here's how to report it.
- Bug within the app: Open an issue within mastodon's repo
- Template not working: Open an issue on xneo1/portainer_templates
- This website not working: Open an issue on lissy93/portainer-templates