Sign inSign up

erseco/alpine-wordpress

By erseco

Updated 1 day ago

WordPress docker image based on Alpine Linux

Image
0

10K+

erseco/alpine-wordpress repository overview

WordPress on Alpine Linux

Docker Pulls Docker Image Size License MIT

WordPress setup for Docker, build on Alpine Linux. The image is only +/- 70MB large.

Repository: https://github.com/erseco/alpine-wordpress

  • Built on the lightweight image https://github.com/erseco/alpine-php-webserver
  • Very small Docker image size (+/-70MB)
  • Uses PHP-FPM for better performance, lower cpu usage & memory footprint
  • Multi-arch support: 386, amd64, arm/v6, arm/v7, arm64, ppc64le, s390x
  • Optimized for 1000 concurrent users
  • Optimized to only use resources when there's traffic (by using PHP-FPM's ondemand PM)
  • Use of runit instead of supervisord to reduce memory footprint
  • docker-compose sample with MariaDB
  • Configuration via ENV variables
  • Easily upgradable to new WordPress versions
  • Includes WP-CLI for command-line management and automation of WordPress tasks, enhancing site management and deployment capabilities.
  • The servers Nginx, PHP-FPM run under a non-privileged user (nobody) to make it more secure
  • The logs of all the services are redirected to the output of the Docker container (visible with docker logs -f <container name>)
  • Follows the KISS principle (Keep It Simple, Stupid) to make it easy to understand and adjust the image to your needs

Usage

Start the Docker containers:

docker-compose up

Login on the system using the provided credentials (ENV vars)

Running Commands as Root

In certain situations, you might need to run commands as root within your WordPress container, for example, to install additional packages. You can do this using the docker-compose exec command with the --user root option. Here's how:

docker-compose exec --user root wordpress sh

WordPress Plugin Development Environment Setup

Below is a docker-compose.yml example specifically designed for WordPress plugin development. This configuration provides a comprehensive setup for developing, testing, and deploying WordPress plugins efficiently.

services:
  mariadb:
    image: mariadb:latest
    restart: unless-stopped
    environment:
      - MYSQL_ROOT_PASSWORD=wordpress
      - MYSQL_DATABASE=wordpress
      - MYSQL_USER=wordpress
      - MYSQL_PASSWORD=wordpress
    volumes:
      - mariadb:/var/lib/mysql

  wordpress:
    image: erseco/alpine-wordpress:latest
    restart: unless-stopped
    depends_on:
      - mariadb
    ports:
      - 8080:8080      
    environment:
      WP_LANGUAGE: es_ES
      WP_ADMIN_USERNAME: admin
      WP_ADMIN_PASSWORD: PLEASE_CHANGEME
      WP_DEBUG: true
      WP_PLUGINS: user-access-manager
      WP_SITE_URL: http://localhost:8080
      POST_CONFIGURE_COMMANDS: |
        echo "Creating user for testing"
        if ! wp user get test1 --field=ID --quiet; then
          wp user create test1 [email protected] --role=subscriber --user_pass=test1
        fi
        echo "Activating plugin"
        wp plugin activate my-plugin
    volumes:
      - wordpress:/var/www/html
      - ./my-plugin:/var/www/html/wp-content/plugins/my-plugin

volumes:
  mariadb: null
  wordpress: null
  • MariaDB service: Configures a MariaDB database with WordPress-specific settings, ensuring data persistence through Docker volumes.
  • WordPress service:
    • Uses erseco/alpine-wordpress:latest, tailored for WordPress development.
    • Sets up WordPress with Spanish language, admin credentials, and enables debugging.
    • Pre-installs and activates specified plugins, including a custom plugin located in ./my-plugin.
    • Executes custom commands after configuration, like creating a test user and activating the developed plugin.
    • Maps port 8080, allowing local access to the WordPress site.
    • Depends on the mariadb service for database connectivity.
How to Use
  1. Save the provided docker-compose.yml in your project directory.
  2. Place your plugin code inside a directory named my-plugin in the same location.
  3. Execute docker-compose up -d in your terminal, within the project directory.
  4. Access your WordPress site at http://localhost:8080 to test and develop your plugin in a real-world environment.

This setup streamlines the plugin development process, from coding and testing to deployment, within a controlled and consistent environment.

Configuration

Define the ENV variables in docker-compose.yml file

Variable NameDefaultDescription
WP_LANGUAGEen_USWordPress site language
DB_HOSTmariadbDatabase host
DB_PORT3306MySQL default port
DB_NAMEwordpressDatabase name
DB_USERwordpressDatabase user
DB_PASSWORDwordpressDatabase password
DB_PREFIXwp_Database prefix for WordPress tables
WP_ADMIN_EMAIL[email protected]WordPress admin email
WP_ADMIN_USERNAMEadminWordPress admin username
WP_ADMIN_PASSWORDPLEASE_CHANGEMEWordPress admin password
WP_DEBUGfalseEnable/disable WordPress debugging
WP_CLI_CACHE_DIR/tmp/wp-cli/cache/WP-CLI cache directory path
WP_THEMEActive WordPress theme
WP_PLUGINSComma-separated list of WordPress plugins
WP_SITE_TITLEWordPress SiteTitle of the WordPress site
WP_SITE_DESCRIPTIONJust another WordPress siteDescription of the WordPress site
WP_SITE_URLhttp://localhost:8080WordPress site URL
client_max_body_size50MMaximum allowed size of client request bodies
post_max_size50MMaximum size of POST data that PHP will accept
upload_max_filesize50MMaximum size of an uploaded file
max_input_vars5000Maximum number of input variables for PHP
zlib_output_compressionOffDisable zlib compresion for PHP
PRE_CONFIGURE_COMMANDSCommands to run before starting the configuration
POST_CONFIGURE_COMMANDSCommands to run after finished the configuration

Tag summary

Content type

Image

Digest

sha256:7caf797e8

Size

99.1 MB

Last updated

1 day ago

docker pull erseco/alpine-wordpress