使用MediaWiki官方Docker镜像添加扩展的最佳方法及实操咨询
Great question! Let's break down your options based on your current setup (using the official MediaWiki Docker image with host volume mounts) and help you pick the best next step.
Option 1: Directly Mount Extension Volumes (Quick & Simple)
This is perfect if you want to test a few extensions quickly or don't need a permanently packaged setup. The official MediaWiki image stores extensions in /var/www/html/extensions, so you can mount your locally downloaded extensions directly into this path.
How to set it up:
- Download the extension: Grab the version of the extension that matches your MediaWiki release (check the extension's documentation for compatibility) and save it to a folder on your host machine, e.g.,
./extensions/VisualEditor. - Update your docker-compose.yml: Add a volume mount for each extension:
services: mediawiki: image: mediawiki:latest volumes: - ./LocalSettings.php:/var/www/html/LocalSettings.php # Mount individual extensions - ./extensions/VisualEditor:/var/www/html/extensions/VisualEditor - ./extensions/ParserFunctions:/var/www/html/extensions/ParserFunctions # Keep your existing volume mounts (like images) - ./images:/var/www/html/images ports: - "8080:80" - Enable the extension: Edit your
LocalSettings.phpto add the extension load command for each one:wfLoadExtension('VisualEditor'); wfLoadExtension('ParserFunctions'); - Fix permissions (if needed): Make sure the extension folders on your host are readable by the container's
www-datauser:sudo chown -R www-data:www-data ./extensions
Pros & Cons:
- ✅ Fast setup, no image rebuilding needed
- ✅ Easy to swap extensions in/out for testing
- ❌ Requires manual management of extension versions and compatibility
- ❌ Dependent on host filesystem; not ideal for production deployments
Option 2: Build a Custom Docker Image (Production-Grade)
If you need a stable, reproducible setup (especially for production), packaging your extensions into a custom image is the way to go. This ensures your extensions are always present, version-locked, and don't rely on host files.
Example Dockerfile:
# Use the exact MediaWiki version you're running (replace 1.39 with your version) FROM mediawiki:1.39 # Install dependencies (git for pulling extensions, composer for PHP-based extensions) RUN apt-get update && apt-get install -y git composer && rm -rf /var/lib/apt/lists/* # Install VisualEditor extension (from Wikimedia's git repo, locked to your MW version) RUN git clone https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor /var/www/html/extensions/VisualEditor RUN cd /var/www/html/extensions/VisualEditor && git checkout REL1_39 # Install ParserFunctions via Composer (handles dependencies automatically) RUN composer require mediawiki/parser-functions:* --working-dir=/var/www/html/extensions/ParserFunctions # Copy your pre-configured LocalSettings.php (with extension enables) into the image COPY LocalSettings.php /var/www/html/LocalSettings.php
Updated docker-compose.yml:
services: mediawiki: # Build from the Dockerfile in the current directory instead of using the official image build: . volumes: # Only mount dynamic data (like uploaded images) – extensions are in the image - ./images:/var/www/html/images ports: - "8080:80"
Pros & Cons:
- ✅ Reproducible environment; extensions are version-locked with MediaWiki
- ✅ No dependency on host filesystem; easy to deploy across multiple servers
- ✅ Automates extension installation and setup
- ❌ Requires rebuilding the image whenever you add/remove/update extensions
Which Should You Choose?
- Go with volume mounts if you're testing extensions, need flexibility, or only have a few to add.
- Build a custom image if you're setting up a production environment, need stability, or have a fixed set of extensions you'll use long-term.
内容的提问来源于stack exchange,提问作者Streamline

