Skip to content

Instantly share code, notes, and snippets.

@joshmoto
Last active November 20, 2024 12:30
Show Gist options
  • Save joshmoto/ab7c09ca45291f7e6f9a14cf070fa70c to your computer and use it in GitHub Desktop.
Save joshmoto/ab7c09ca45291f7e6f9a14cf070fa70c to your computer and use it in GitHub Desktop.
/db
/plugins
/uploads
/logs
version: '3.7'
networks:
wordpress:
ipam:
config:
- subnet: 172.25.0.0/16
services:
# here is our mysql database
db:
image: mysql:5.7
volumes:
- ./db:/var/lib/mysql:delegated
ports:
- "3306:3306"
restart: always
environment:
MYSQL_ROOT_PASSWORD: somewordpress
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
networks:
- wordpress
# here is our wordpress server
wordpress:
depends_on:
- db
image: wordpress:latest
volumes:
# our persistent local data re routing
- ./themes/yourtheme:/var/www/html/wp-content/themes/yourtheme:delegated
- ./plugins:/var/www/html/wp-content/plugins
- ./mu-plugins:/var/www/html/wp-content/mu-plugins
- ./uploads:/var/www/html/wp-content/uploads
- ./logs:/var/www/html/wp-content/logs
- ./uploads.ini:/usr/local/etc/php/conf.d/uploads.ini
- ./error-logging.ini:/usr/local/etc/php/conf.d/error-logging.ini
ports:
- "80:80"
restart: always
networks:
- wordpress
environment:
# debug mode
WORDPRESS_DEBUG: 1
# docker wp config settings
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
WORDPRESS_DB_NAME: wordpress
WORDPRESS_TABLE_PREFIX: wp_
WORDPRESS_AUTH_KEY: 5f6ede1b94d25a2294e29eeba929a8c80a5ac0fb
WORDPRESS_SECURE_KEY: 5f6ede1b94d25a2294e29eeba929a8c80a5ac0fb
WORDPRESS_LOGGED_IN_KEY: 5f6ede1b94d25a2294e29eeba929a8c80a5ac0fb
WORDPRESS_NONCE_KEY: 5f6ede1b94d25a2294e29eeba929a8c80a5ac0fb
WORDPRESS_SECURE_AUTH_SALT: 5f6ede1b94d25a2294e29eeba929a8c80a5ac0fb
WORDPRESS_LOGGED_IN_SALT: 5f6ede1b94d25a2294e29eeba929a8c80a5ac0fb
WORDPRESS_NONCE_SALT: 5f6ede1b94d25a2294e29eeba929a8c80a5ac0fb
# our local dev environment
WORDPRESS_CONFIG_EXTRA: |
/* development parameters */
define('WP_CACHE', false);
define('ENVIRONMENT', 'local');
/* do not re-define WP_DEBUG here or it will throw a blank error in the admin */
/* you can remove this entirely, this is just to show you what not to do */
// define('WP_DEBUG', true);
if (!defined('WP_HOME')) {
/* force our home url */
define('WP_HOME', 'http://localhost');
define('WP_SITEURL', WP_HOME);
}
error_reporting = E_ERROR | E_WARNING | E_PARSE | E_CORE_ERROR | E_CORE_WARNING | E_COMPILE_ERROR | E_COMPILE_WARNING | E_RECOVERABLE_ERROR
display_errors = Off
display_startup_errors = Off
log_errors = On
error_log = /var/www/html/wp-content/logs/debug.log
log_errors_max_len = 1024
ignore_repeated_errors = On
ignore_repeated_source = Off
html_errors = Off
file_uploads = On
memory_limit = 2000M
upload_max_filesize = 2000M
post_max_size = 2000M
max_execution_time = 600
@pixolin
Copy link

pixolin commented Nov 9, 2024

Thank you for sharing your Docker compose file. I find it particularly helpful how you include different settings for PHP. Allow me a few comments:

  • According to the WordPress documentation, define('ENVIRONMENT', 'local'); should be replaced by define('WP_ENVIRONMENT', 'local'); (or development, staging, and productionrespectively). At least if you want to use a plugin like Display Environment Type for your development website.

  • To use the plugin Intellephense in VS Code, I only use

volumes:
  - ./wordpress:/var/www/html
  - ./uploads.ini:/usr/local/etc/php/conf.d/uploads.ini
  - ./error-logging.ini:/usr/local/etc/php/conf.d/error-logging.ini

instead of the volumes you use for themes, plugins and mu-plugins. This way I can load all files of the WordPress installation into VS Code, which e.g. makes it easy to look up core function definitions.

  • I am also missing a setup to use WordPress Coding Standards with PHP Code Sniffer and wonder, of that may be included into the Docker file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment