Pixelfed docker-compose.yml example

This was Dan's work and his Docker container which merges most of the recent DEV branch fixes from pixelfed as they do not have a standard container as it's usually built from scratch.. which you can do but this one works. If you want a bit of drama then read the devs ;-) This is a modified example from a homelabos instance so the volumes if you are using homelabos would be something like /var/homelabos/pixelfed but I have specified ./  in the example here so set this up to reflect where you want persistent volumes to live.

If, like me, you had several broken attempts then a good prune of docker containers and volumes before you start is good idea.. Careful now. For example:

$docker system prune --volumes

---
version: '3'

networks:
  traefik_network:
    external:
      name: homelabos_traefik
  pixelfed:

services:
  pixelfed:
    image: dmacedo/pixelfed:latest
    restart: unless-stopped
    networks:
      - traefik_network
      - pixelfed
    labels:
      - "traefik.http.services.pixelfed.loadbalancer.server.scheme=http"
      - "traefik.http.services.pixelfed.loadbalancer.server.port=80"
      - "traefik.enable=true"
      - "traefik.docker.network=homelabos_traefik"
      - "traefik.http.routers.pixelfed-http.service=pixelfed"
      - "traefik.http.routers.pixelfed-http.rule=Host(`pixelfed.<DOMAIN>`)"
      - "traefik.http.routers.pixelfed-http.entrypoints=http"
      - "traefik.http.routers.pixelfed-http.middlewares=redirect@file, customFrameHomelab@file"
      - "traefik.http.routers.pixelfed.service=pixelfed"
      - "traefik.http.routers.pixelfed.rule=Host(`pixelfed.<DOMAIN>`)"
      - "traefik.http.routers.pixelfed.entrypoints=https"
      - "traefik.http.routers.pixelfed.middlewares=customFrameHomelab@file"
      - "traefik.http.routers.pixelfed.tls=true"
      - "traefik.http.routers.pixelfed.tls.certresolver=http"
    env_file:
      - "./pixelfed/pixelfed.env"
    environment:
      - APP_KEY=<GENERATED ON FIRST RUN - FROM pixelfed.env>
      - DB_PASSWORD=<PASSWORD_NO QUOTES>
    volumes:
      - "./pixelfed/pixelfed.env:/var/www/.env"
      - "./pixelfed/storage:/var/www/storage"

  worker: # Comment this whole block if HORIZON_EMBED is true.
    image: dmacedo/pixelfed:latest
    networks:
      - pixelfed
    restart: unless-stopped
    env_file:
      - "./pixelfed/pixelfed.env"
    environment:
      - DB_PASSWORD=<PASSWORD_NO_QUOTES>
    volumes:
      - "./pixelfed/storage:/var/www/storage"
    command: gosu www-data php artisan horizon

  db:
    image: mariadb:10.4
    restart: unless-stopped
    networks:
      - pixelfed
    environment:
      - MYSQL_DATABASE=pixelfed
      - MYSQL_PASSWORD=<PASSWORD_NO_QUOTES>
      - MYSQL_USER=pixelfed
      - MYSQL_ROOT_PASSWORD=<ROOT_PASSWORD>
    volumes:
      - "./pixelfed/mysql:/var/lib/mysql"

  redis:
    image: redis:6-alpine
    restart: unless-stopped
    networks:
      - pixelfed
    volumes:
      - "./pixelfed/redis:/data"
    command: >
     --requirepass <REDIS_PASS_NO_QUOTES>

# Note: Provide a <PASSWORD_NO_QUOTES> for the db
# Provide a <ROOT+PASSWORD> for mysql
# Provide a <REDIS_PASS_NO_QUOTES>
# If you run into problems, check that any other docker containers you are running
# on your system all have 'redis' 'db' etc all ruuning on separate networks
# My instance took a while to debug as I had a leaky redis from another container.
# Docker ps -a will list running containers - check ports for redis and mysql to debug
# Any stray networks
# Portainer can be useful to debug

pixefed.env looks like this. You don't need to worry too much about the SMTP stuff as you can later edit that from the application under admin settings ;-) Mailgun I would suggest here if you don't want the hassle of running a mail server. You need it if you federate and invite users etc.

The --requirepass for the redis section does indeed look shonky, but it does work 

APP_NAME="Pix"
ADMIN_ENV_EDITOR=true
APP_ENV=production
APP_KEY=<LEAVE BLANK ON FIRST RUN>
APP_DEBUG=false

APP_URL="https://pixelfed.<DOMAIN>"
APP_DOMAIN=pixelfed.<DOMAIN>
ADMIN_DOMAIN=pixelfed.<DOMAIN>
SESSION_DOMAIN=pixelfed.<DOMAIN>
SESSION_SECURE_COOKIE=false
TRUST_PROXIES="*"

LOG_CHANNEL=stack

DB_CONNECTION=mysql
DB_HOST=db
DB_PORT=3306
DB_DATABASE=pixelfed
DB_PASSWORD=<PASSWORD_NO_QUOTES>
DB_USERNAME=pixelfed

BROADCAST_DRIVER=log
LOG_CHANNEL=stderr
CACHE_DRIVER=redis
SESSION_DRIVER=redis
SESSION_LIFETIME=120
QUEUE_DRIVER=redis
# log channel stderr was a Dan Eureka moment


REDIS_HOST=redis
REDIS_PASSWORD=<REDIS_PASSWORD>
REDIS_PORT=6379
# Redis really hates company
# Make sure no other uncontained redis


MAIL_DRIVER=smtp
MAIL_HOST=
MAIL_PORT=
MAIL_USERNAME=
MAIL_PASSWORD=
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS=
MAIL_FROM_NAME=
# Can be updated from within app

OPEN_REGISTRATION=true
ENFORCE_EMAIL_VERIFICATION=false
PF_MAX_USERS=20

MAX_PHOTO_SIZE=15000
MAX_CAPTION_LENGTH=150
MAX_ALBUM_LENGTH=4

ACTIVITY_PUB=false
REMOTE_FOLLOW=false
ACTIVITYPUB_INBOX=false
ACTIVITYPUB_SHAREDINBOX=false
# Set these "true" to enable federation.
# You might need to also run:
#   php artisan cache:clear
#   php artisan optimize:clear
#   php artisan optimize

PF_COSTAR_enable=true
CS_BLOCKED_DOMAINS='gab.com,gab.ai,develop.gab.com'
CS_CW_DOMAINS='switter.at'
CS_UNLISTED_DOMAINS='example.org,example.net,example.com'

# Optional
HORIZON_DARKMODE=false  # Horizon theme darkmode
HORIZON_EMBED=false  # Single Docker Container mode

First start

On the first start of everything the database needs to be initialized. This happens automatically, but takes some seconds.

Start everything with docker-compose up -d and wait for it. You can watch the progress of the start with docker-compose logs -f app.

This is how you debug it. When working out why I could get no initial web interface I found that I had some redis and db instances not properly confined to their docker containers. The plus side is that it forced me to fix everything and set other things up properly,

docker ps -a will show running containers.

docker ps | grep 6379 will list containers running redis on this common redis port number ;-)

So, If Pixelfed chokes, it's possibly this or a mysql failing to connect for similar reasons

docker ps | grep 3306  might be handy to see if you have any databases not constrained to the own internal network.

After the start is complete, register your account through the web interface, and run docker-compose exec pixelfed php artisan user:admin YOURUSERNAME to grant yourself admin rights.

When testing with Dan, we found that you can Register an account from the web interface then:

docker-compose exec pixelfed php artisan user:admin 1

Easier.

Good luck. It was a fickle adversary but we got there in the end. It's a good project and pretty much *Instagram* without shouty adverts.

https://pixelfed.lazysquirrel.co.uk/p/Bumblebee/

That's mine there.