HUB
Sign inSign up

cerealcable/flarum

By cerealcable

•Updated 4 days ago

Image
0

4.5K

cerealcable/flarum repository overview

⁠Flarum

Flarum⁠ forum software on Alpine Linux, with Apache and PHP. It installs itself on first boot, and on every later start it runs the database migrations and publishes extension assets.

  • PHP compiled from php.net's release tarball, with the signature checked against PHP's release manager keys before it's built, so PHP security fixes don't wait on Alpine packages
  • Flarum 2.0 on PHP 8.5, and Flarum 1.8 on PHP 8.3 for forums not ready to migrate yet
  • Flarum's task scheduler⁠ runs inside the container, so there's no host cron job to set up
  • flarum/realtime is bundled, and you can run its websocket daemon from the same image
  • linux/amd64 and linux/arm64
  • Signed with cosign (verify⁠)

⁠Tags

TagLinePHP
latest, 2, 2.0, 2.0.0Flarum 2.08.5
1, 1.8, 1.8.20Flarum 1.8 (maintenance)8.3

latest follows the 2.0 line, so pin 1.8 to stay on Flarum 1.8. On the 2.0 line the version tag is the flarum/flarum release. Flarum core and the bundled extensions are the newest 2.0.x releases available when the image was built, and docker exec <container> php flarum info shows the exact versions. On the 1.8 line the version tag is the flarum/core version.

⁠Quick start

compose.yaml:

services:
  flarum:
    image: cerealcable/flarum:2.0
    restart: unless-stopped
    ports:
      - "8080:80"
    environment:
      DB_HOST: mysql
      DB_PASS: change-me
      FLARUM_BASE_URL: http://localhost:8080
      FLARUM_TITLE: My Forum
      FLARUM_ADMIN_USER: admin
      FLARUM_ADMIN_PASS: change-me-too
      FLARUM_ADMIN_EMAIL: [email protected]
    volumes:
      - flarum-config:/var/flarum-config
      - flarum-assets:/var/www/html/public/assets
      - flarum-storage:/var/www/html/storage
    depends_on:
      mysql:
        condition: service_healthy

  mysql:
    image: mysql:9.7
    restart: unless-stopped
    environment:
      MYSQL_DATABASE: flarum
      MYSQL_USER: flarum
      MYSQL_PASSWORD: change-me
      MYSQL_ROOT_PASSWORD: change-me-root
    volumes:
      - mysql-data:/var/lib/mysql
    healthcheck:
      test: ["CMD", "mysqladmin", "ping", "-h", "localhost"]
      interval: 10s
      retries: 10

volumes:
  flarum-config:
  flarum-assets:
  flarum-storage:
  mysql-data:
docker compose up -d

Open http://localhost:8080 and log in with the admin account. The first boot waits for the database, runs the installer and starts Apache, which takes a few seconds.

⁠Environment variables

VariableDefaultNotes
DB_HOSTmysql
DB_PORT3306
DB_NAMEflarum
DB_USERflarum
DB_PASSRequired on first boot
DB_PREFIXemptyTable prefix
FLARUM_BASE_URLRequired on first boot; the public URL
FLARUM_TITLEMy Flarum
FLARUM_ADMIN_USERadmin
FLARUM_ADMIN_PASSRequired on first boot
FLARUM_ADMIN_EMAIL[email protected]

These are only used by the first-boot installer, which writes them to config.php. Changing them later has no effect: edit config.php or use the admin panel instead.

⁠Volumes

PathContents
/var/flarum-configconfig.php
/var/www/html/public/assetsUploaded avatars, logos, files
/var/www/html/storageCache, logs, sessions

Persist all three, along with the database.

⁠config.php

config.php lives in /var/flarum-config. When it doesn't exist, the first boot generates it from the environment variables above. You can also provide your own, for example deployed by configuration management. When the file is already there, the installer is skipped and the container only runs migrations. On an empty database that means no admin user is created.

The URL in config.php (url) must be the address browsers use, including https:// when the forum is behind a TLS proxy.

⁠Extensions

The image ships Flarum's first-party extensions, which you enable in the admin panel. Flarum's code lives in the image, not in a volume, so an extension installed with composer require inside a running container disappears when the container is recreated. Build your own image on top of this one instead:

FROM cerealcable/flarum:2.0
RUN composer require --no-interaction --no-progress fof/upload \
    && chown -R apache:apache /var/www/html/vendor \
         /var/www/html/composer.json /var/www/html/composer.lock

Use that image in place of cerealcable/flarum. On the next start the container publishes the extension's assets. Enable it in the admin panel, or with docker exec <container> su-exec apache php flarum extension:enable fof-upload. Rebuild your image whenever you pull a newer base tag.

⁠Scheduler

Flarum runs periodic tasks through its scheduler, which needs php flarum schedule:run called every minute. The container does that itself: crond starts alongside Apache and runs the scheduler as the web user, so there's no host cron job or extra container to set up.

Core schedules a few housekeeping tasks, such as refreshing announcements and syncing the list of abandoned extensions. Extensions can add their own, such as sitemap generation or digest emails. To list them:

docker exec <container> su-exec apache php flarum schedule:list

To check the scheduler is running, look at the admin dashboard, which shows the scheduler as Active, or run:

docker exec <container> su-exec apache php flarum info

This should print Scheduler status: Active. The scheduler's output goes to docker logs, including a No scheduled commands are ready to run line every minute when nothing is due.

Only the main container runs the scheduler. Sidecars started with a command, like the Realtime daemon below, don't. If you run more than one web container against the same database, each one runs the scheduler, so tasks run once per container.

Queued jobs, such as notification emails, run inside the web request, because the installer sets Flarum's queue driver to sync. No queue worker is needed.

⁠Realtime

To use flarum/realtime⁠, run a second container from the same image with the websocket daemon as its command. When the container is given a command, it waits for config.php and runs the command as the web user instead of starting Apache:

  realtime:
    image: cerealcable/flarum:2.0
    command: php flarum realtime:serve
    restart: unless-stopped
    volumes:
      - flarum-config:/var/flarum-config
      - flarum-storage:/var/www/html/storage

Add a websocket block to config.php. Browsers connect through your reverse proxy on 443, and Flarum talks to the daemon directly over the Docker network:

  'websocket' => array (
    'server-host' => '0.0.0.0',
    'server-port' => 6001,
    'js-client-port' => 443,
    'js-client-secure' => true,
    'php-client-host' => 'realtime',
    'php-client-port' => 6001,
    'php-client-secure' => false,
  ),

Then enable Realtime in the admin panel, and route /app on the forum's hostname to the realtime container on port 6001, as in the proxy examples below.

⁠Reverse proxy

The container serves plain HTTP on port 80. Put a TLS-terminating proxy in front of it, and set url in config.php to the public https:// address. The examples assume the proxy shares a Docker network with the flarum and realtime services, so you can drop the ports: mapping. The /app routes are only needed with Realtime.

⁠Traefik

Traefik supports websockets and passes Host through by default. As labels:

services:
  flarum:
    image: cerealcable/flarum:2.0
    labels:
      traefik.enable: "true"
      traefik.http.routers.flarum.rule: Host(`forum.example.com`)
      traefik.http.routers.flarum.entrypoints: websecure
      traefik.http.routers.flarum.tls.certresolver: letsencrypt
      traefik.http.services.flarum.loadbalancer.server.port: "80"
    networks:
      - proxy
      - default

  realtime:
    image: cerealcable/flarum:2.0
    command: php flarum realtime:serve
    labels:
      traefik.enable: "true"
      traefik.http.routers.flarum-realtime.rule: Host(`forum.example.com`) && PathPrefix(`/app`)
      traefik.http.routers.flarum-realtime.entrypoints: websecure
      traefik.http.routers.flarum-realtime.tls.certresolver: letsencrypt
      traefik.http.services.flarum-realtime.loadbalancer.server.port: "6001"
    networks:
      - proxy
      - default

networks:
  proxy:
    external: true

Swap websecure, letsencrypt and proxy for your own entrypoint, certificate resolver and network names. Traefik picks the longer rule first, so /app goes to the daemon and everything else goes to the forum. If the containers are on more than one network, set traefik.docker.network: proxy so Traefik uses the right one.

⁠Caddy
forum.example.com {
	reverse_proxy /app/* realtime:6001
	reverse_proxy flarum:80
}
⁠nginx

nginx needs explicit websocket headers for /app, and a body size limit that matches PHP's 64 MB upload limit:

map $http_upgrade $connection_upgrade {
    default upgrade;
    ''      close;
}

server {
    listen 443 ssl;
    server_name forum.example.com;

    ssl_certificate     /etc/ssl/forum.example.com.crt;
    ssl_certificate_key /etc/ssl/forum.example.com.key;

    client_max_body_size 64m;

    location /app/ {
        proxy_pass http://realtime:6001;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection $connection_upgrade;
        proxy_set_header Host $host;
        proxy_read_timeout 1h;
    }

    location / {
        proxy_pass http://flarum:80;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}

⁠Upgrading

Pull the new tag and recreate the container. Pending migrations run on start. Back up the database first, and read Flarum's release notes before moving between major versions, such as from 1.8 to 2.0.

⁠Verifying the image

Images are signed with cosign. Save this public key as cerealcable.pub:

-----BEGIN PUBLIC KEY-----
MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAExjdgFfwLu7CHXs9+z+v7oCsWY4mo
khNFQ6ww0cKxCZR3HndkaKftoiGAgzitBQ13fL2ZPxobUv5HicDnL4idMg==
-----END PUBLIC KEY-----

Then:

cosign verify --key cerealcable.pub cerealcable/flarum:2.0

⁠License

Flarum is licensed under the MIT License⁠. This image is maintained by cerealcable and is not affiliated with the Flarum project. Please report Flarum bugs upstream⁠.

Tag summary
Recent tags
Content type
Image
Digest
sha256:751d964a3…
Size
50.3 MB
Last updated
15 days ago
docker pull cerealcable/flarum:latest