Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ on:
inputs:
mybb_version:
description: 'MyBB version to build (e.g., 1839)'
required: false
required: true
default: '1839'

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
# Latest MyBB version - update this when new MyBB versions are released
LATEST_MYBB_VERSION: '1839'

jobs:
build-and-push:
Expand Down Expand Up @@ -73,11 +75,12 @@ jobs:
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
MYBB_VERSION=${{ github.event.inputs.mybb_version || '1839' }}
MYBB_VERSION=${{ github.event.inputs.mybb_version || env.LATEST_MYBB_VERSION }}
cache-from: type=gha
cache-to: type=gha,mode=max

# Build multiple MyBB versions on release
# Build images for the 2 latest MyBB versions on release
# Update this matrix when new MyBB versions are released
build-versions:
if: startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-latest
Expand All @@ -86,7 +89,9 @@ jobs:
packages: write
strategy:
matrix:
mybb_version: ['1836', '1837', '1838', '1839']
# Only the 2 latest MyBB versions are built to reduce maintenance burden
# Update these versions when new MyBB releases come out
mybb_version: ['1838', '1839']

steps:
- name: Checkout repository
Expand Down
35 changes: 31 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@ FROM php:8.2-apache

# OCI Labels for GitHub Container Registry
LABEL org.opencontainers.image.source="https://github.com/visualcookie/mybb"
LABEL org.opencontainers.image.description="MyBB Forum Software - Flexible Docker image supporting any MyBB version"
LABEL org.opencontainers.image.description="MyBB Forum Software - Pre-built Docker image with MyBB included"
LABEL org.opencontainers.image.licenses="MIT"
LABEL org.opencontainers.image.title="MyBB Docker"
LABEL org.opencontainers.image.vendor="visualcookie"

# Build argument for MyBB version (can be overridden at build time)
ARG MYBB_VERSION=1839
# Build argument for MyBB version (REQUIRED at build time)
ARG MYBB_VERSION

# Environment variables
ENV MYBB_VERSION=${MYBB_VERSION}
ENV APACHE_DOCUMENT_ROOT=/var/www/html
# Directory where MyBB is pre-installed at build time
ENV MYBB_SOURCE_DIR=/opt/mybb-source

# Install system dependencies
RUN apt-get update && apt-get install -y \
Expand All @@ -25,6 +27,7 @@ RUN apt-get update && apt-get install -y \
unzip \
curl \
wget \
rsync \
&& rm -rf /var/lib/apt/lists/*

# Configure and install PHP extensions required by MyBB
Expand Down Expand Up @@ -61,6 +64,29 @@ RUN { \
echo 'opcache.fast_shutdown=1'; \
} > /usr/local/etc/php/conf.d/opcache-recommended.ini

# Download and install MyBB at build time (not runtime)
# This ensures the image contains a specific MyBB version and eliminates runtime download risks
RUN set -eux; \
if [ -z "${MYBB_VERSION}" ]; then \
echo "ERROR: MYBB_VERSION build argument is required"; \
exit 1; \
fi; \
mkdir -p ${MYBB_SOURCE_DIR}; \
echo "Downloading MyBB version ${MYBB_VERSION}..."; \
wget -q -O /tmp/mybb.zip "https://github.com/mybb/mybb/releases/download/mybb_${MYBB_VERSION}/mybb_${MYBB_VERSION}.zip" \
|| wget -q -O /tmp/mybb.zip "https://resources.mybb.com/downloads/mybb_${MYBB_VERSION}.zip"; \
unzip -q /tmp/mybb.zip -d /tmp/mybb_extract; \
if [ -d "/tmp/mybb_extract/Upload" ]; then \
cp -r /tmp/mybb_extract/Upload/* ${MYBB_SOURCE_DIR}/; \
elif [ -d "/tmp/mybb_extract/upload" ]; then \
cp -r /tmp/mybb_extract/upload/* ${MYBB_SOURCE_DIR}/; \
else \
cp -r /tmp/mybb_extract/*/* ${MYBB_SOURCE_DIR}/ 2>/dev/null || cp -r /tmp/mybb_extract/* ${MYBB_SOURCE_DIR}/; \
fi; \
rm -rf /tmp/mybb.zip /tmp/mybb_extract; \
echo "MyBB ${MYBB_VERSION} installed to ${MYBB_SOURCE_DIR}"; \
echo "${MYBB_VERSION}" > ${MYBB_SOURCE_DIR}/.mybb_version

# Set working directory
WORKDIR /var/www/html

Expand All @@ -75,7 +101,8 @@ RUN mkdir -p /var/www/html/uploads \
/var/www/html/admin/backups

# Set proper permissions
RUN chown -R www-data:www-data /var/www/html
RUN chown -R www-data:www-data /var/www/html \
&& chown -R www-data:www-data ${MYBB_SOURCE_DIR}

# Expose port 80
EXPOSE 80
Expand Down
137 changes: 29 additions & 108 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
![GitHub License](https://img.shields.io/github/license/visualcookie/mybb?style=for-the-badge)
![GHCR](https://img.shields.io/badge/ghcr.io-visualcookie%2Fmybb-blue?style=for-the-badge&logo=docker) ![Assisted Using Claude](https://img.shields.io/badge/Claude-D97757?style=for-the-badge&logo=claude&logoColor=white)

A flexible Docker image for [MyBB](https://mybb.com/) forum software that supports any version of MyBB.
A Docker image for [MyBB](https://mybb.com/) forum software with MyBB baked into the image at build time.

## Features

- 🐳 Easy deployment with Docker or Docker Compose
- 🔄 Support for any MyBB version (configurable)
- 📦 MyBB pre-installed in the image (no runtime downloads)
- 💾 Persistent data storage with Docker volumes
- 🔒 Secure default configuration
- 🚀 Optimized PHP configuration for MyBB
- ⬆️ Safe upgrade mode preserving configs, uploads, themes, and plugins
- ⬆️ Automatic file sync preserving existing configs on upgrade
- ❤️ Health checks for container orchestration
- 📂 Optional SFTP server for file management (themes, plugins, updates)
- 📦 Optional phpMyAdmin for database management
Expand All @@ -29,7 +29,7 @@ There's an example [Docker compose file](./docker-compose.ghcr.yml) in this repo

1. **Build the image:**
```bash
docker build -t mybb .
docker build --build-arg MYBB_VERSION=1839 -t mybb .
```

2. **Create a network:**
Expand All @@ -56,7 +56,6 @@ There's an example [Docker compose file](./docker-compose.ghcr.yml) in this repo
--name mybb-forum \
--network mybb-network \
-p 8080:80 \
-e MYBB_VERSION=1839 \
-e DB_HOST=mybb-db \
-e DB_USER=mybb \
-e DB_PASSWORD=mybb_password \
Expand Down Expand Up @@ -84,28 +83,30 @@ There's an example [Docker compose file](./docker-compose.ghcr.yml) in this repo

| Variable | Description | Default |
|----------|-------------|---------|
| `MYBB_VERSION` | MyBB version number (e.g., 1839) | `1839` |
| `MYBB_VERSION` | MyBB version (build argument) | `1839` |
| `MYBB_PORT` | Web server port | `8080` |
| `DB_HOST` | Database hostname | - |
| `DB_PORT` | Database port | `3306` |
| `DB_USER` | Database username | `root` |
| `DB_PASSWORD` | Database password | - |
| `DB_NAME` | Database name | `mybb` |
| `FORCE_REINSTALL` | Force reinstall MyBB | `false` |
| `SFTP_PORT` | SFTP server port | `2222` |
| `SFTP_USER` | SFTP username | `mybb` |
| `SFTP_PASSWORD` | SFTP password | `mybb_sftp_pass` |
| `PMA_PORT` | phpMyAdmin port | `8081` |
| `TZ` | Timezone | `UTC` |
| `UPGRADE_MODE` | Enable safe upgrade mode | `false` |
| `PRESERVE_PLUGINS` | Keep plugins during upgrade | `true` |
| `PRESERVE_THEMES` | Keep themes during upgrade | `true` |

### MyBB Versions

You can use any MyBB version by setting `MYBB_VERSION` in your `.env` file. The version is downloaded at container startup.
MyBB is baked into the image at build time. Pre-built images are available for the 2 latest versions:

```bash
docker pull ghcr.io/visualcookie/mybb:latest # 1839
docker pull ghcr.io/visualcookie/mybb:1839
docker pull ghcr.io/visualcookie/mybb:1838
```

To build a different version locally:

Find all available versions at: https://github.com/mybb/mybb/releases
```bash
docker build --build-arg MYBB_VERSION=1837 -t mybb:1837 .
```

## Volumes

Expand Down Expand Up @@ -215,97 +216,25 @@ After starting the containers, complete the MyBB setup:
docker exec mybb-forum rm -rf /var/www/html/install
```

## Upgrading MyBB (Safe Upgrade Mode)

This image includes a **safe upgrade mode** that preserves your configuration, uploads, themes, and plugins while updating MyBB core files.

### Quick Upgrade Steps

1. **Edit `.env`** - Set the new version and enable upgrade mode:
```bash
MYBB_VERSION=1839
UPGRADE_MODE=true
```

2. **Rebuild and restart:**
```bash
docker compose down
docker compose build --no-cache
docker compose up -d
```
## Upgrading MyBB

3. **Complete the upgrade:**
- Visit `http://localhost:8080/install/upgrade.php`
- Follow the upgrade wizard (this migrates your database)

4. **Cleanup:**
```bash
# Remove the install folder
docker exec mybb-forum rm -rf /var/www/html/install

# Remove the upgrade reminder file
docker exec mybb-forum rm -f /var/www/html/UPGRADE_IN_PROGRESS.txt

# Disable upgrade mode in .env
# UPGRADE_MODE=false (or remove the line)
```

### What Gets Preserved

| Item | Preserved | Notes |
|------|-----------|-------|
| `inc/config.php` | ✅ Always | Database configuration |
| `inc/settings.php` | ✅ Always | Forum settings |
| `uploads/` | ✅ Always | User avatars, attachments |
| `inc/plugins/` | ✅ Default | Set `PRESERVE_PLUGINS=false` to reset |
| `images/` | ✅ Default | Set `PRESERVE_THEMES=false` to reset |
| `inc/languages/` | ✅ Always | Language customizations |

### What Gets Updated

- All core PHP files
- JavaScript files
- Default images/icons
- Install/upgrade scripts

### Upgrade Environment Variables

| Variable | Description | Default |
|----------|-------------|---------|
| `UPGRADE_MODE` | Enable safe upgrade mode | `false` |
| `PRESERVE_PLUGINS` | Keep existing plugins | `true` |
| `PRESERVE_THEMES` | Keep existing themes | `true` |

### Automatic Backups

Before upgrading, the script automatically backs up critical files to `/var/www/html/admin/backups/`:
- `pre_upgrade_TIMESTAMP_config.php`
- `pre_upgrade_TIMESTAMP_settings.php`
- `pre_upgrade_TIMESTAMP_plugins_list.txt`
- `pre_upgrade_TIMESTAMP_themes_list.txt`

### Manual Backup (Recommended)

For extra safety, create a full backup before upgrading:
To upgrade, pull/build a new image and restart. The entrypoint syncs new files while preserving existing ones (config, uploads, plugins, themes).

```bash
# Backup files
docker exec mybb-forum tar -czvf /tmp/mybb-backup.tar.gz /var/www/html
docker cp mybb-forum:/tmp/mybb-backup.tar.gz ./mybb-backup.tar.gz
# Update image tag in docker-compose.ghcr.yml, then:
docker compose down && docker compose pull && docker compose up -d

# Backup database
docker exec mybb-database mysqldump -u mybb -p mybb > mybb-database-backup.sql
# Or rebuild locally with new version:
docker compose down
docker compose build --build-arg MYBB_VERSION=1840
docker compose up -d
```

### Alternative: Manual Upgrade via SFTP
After restart, visit `/install/upgrade.php` if MyBB requires database migrations, then delete the install folder:

If you prefer manual control, use SFTP:

1. Download new MyBB from [mybb.com](https://mybb.com/download/)
2. Connect via SFTP (see SFTP section above)
3. Upload new files, but **skip** `inc/config.php`
4. Visit `/install/upgrade.php`
5. Delete the install folder
```bash
docker exec mybb-forum rm -rf /var/www/html/install
```

## Troubleshooting

Expand All @@ -331,14 +260,6 @@ docker exec mybb-forum chmod -R 777 /var/www/html/uploads /var/www/html/cache
- Verify credentials in `.env` match the installation wizard inputs
- Check if the network is properly configured

### Force reinstall MyBB
```bash
docker run -d \
--name mybb-forum \
-e FORCE_REINSTALL=true \
...
```

## Security Recommendations

1. **Change default passwords** in `.env` (database, SFTP)
Expand Down
8 changes: 0 additions & 8 deletions docker-compose.ghcr.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# Docker Compose file using pre-built image from GitHub Container Registry
# Usage: docker compose -f docker-compose.ghcr.yml up -d

services:
mybb:
image: ghcr.io/visualcookie/mybb:${MYBB_TAG:-latest}
Expand All @@ -9,17 +6,12 @@ services:
ports:
- "${MYBB_PORT:-8080}:80"
environment:
- MYBB_VERSION=${MYBB_VERSION:-1839}
- DB_HOST=mybb-db
- DB_PORT=3306
- DB_USER=${MYSQL_USER:-mybb}
- DB_PASSWORD=${MYSQL_PASSWORD:-mybb_password}
- DB_NAME=${MYSQL_DATABASE:-mybb}
- TZ=${TZ:-UTC}
# Upgrade mode options
- UPGRADE_MODE=${UPGRADE_MODE:-false}
- PRESERVE_PLUGINS=${PRESERVE_PLUGINS:-true}
- PRESERVE_THEMES=${PRESERVE_THEMES:-true}
volumes:
- mybb_data:/var/www/html
depends_on:
Expand Down
5 changes: 0 additions & 5 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,12 @@ services:
ports:
- "${MYBB_PORT:-8080}:80"
environment:
- MYBB_VERSION=${MYBB_VERSION:-1839}
- DB_HOST=mybb-db
- DB_PORT=3306
- DB_USER=${MYSQL_USER:-mybb}
- DB_PASSWORD=${MYSQL_PASSWORD:-mybb_password}
- DB_NAME=${MYSQL_DATABASE:-mybb}
- TZ=${TZ:-UTC}
# Upgrade mode options
- UPGRADE_MODE=${UPGRADE_MODE:-false}
- PRESERVE_PLUGINS=${PRESERVE_PLUGINS:-true}
- PRESERVE_THEMES=${PRESERVE_THEMES:-true}
volumes:
# Main webroot volume (shared with SFTP)
- mybb_data:/var/www/html
Expand Down
Loading