Last active
April 29, 2022 18:41
-
-
Save SeanSith/80155887f6bd3c828edebf22f2947c15 to your computer and use it in GitHub Desktop.
Docker-Compose definition for a light Wordpress Stack
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# A Docker Compose setup for running most Wordpress environments | |
# | |
# Setup: | |
# 1. Configure wp-config.php to either pull the environment variables in | |
# services.web.environment or use the same settings. | |
# 2. Optionally put a database dump in the project root which will get imported | |
# on first project boot. This will remain persistent, so if you need to wipe | |
# the database, `docker volume ls` will help you find it and | |
# `docker volume rm [volume name]` to remove it. | |
# 3. `docker-compose up` | |
version: '3' | |
services: | |
web: | |
image: nginx:latest | |
ports: | |
- '8080:80' | |
volumes: | |
- './:/var/www/html' | |
environment: | |
- DB_HOST='database' | |
- DB_NAME='database' | |
- DB_USER='root' | |
- DB_PASSWORD='' | |
- WP_SITEURL='http://localhost:8080' | |
- WP_HOME='http://localhost:8080' | |
command: > | |
sh -c "echo ' | |
server { | |
listen 80 default_server; | |
listen [::]:80 default_server; | |
server_name localhost; | |
index index.php index.html; | |
root /var/www/html/site; | |
location / { | |
try_files $$uri $$uri/ /index.php?$$args; | |
} | |
location ~ \.php$$ { | |
fastcgi_split_path_info ^(.+\.php)(/.+)$$; | |
try_files $$uri =404; | |
fastcgi_pass php:9000; | |
fastcgi_index index.php; | |
include fastcgi_params; | |
fastcgi_param SCRIPT_FILENAME $$document_root$$fastcgi_script_name; | |
fastcgi_param PHP_VALUE \"memory_limit = 1024M\"; | |
set $$path_info $$fastcgi_path_info; | |
fastcgi_param PATH_INFO $$fastcgi_path_info; | |
fastcgi_param DB_HOST $$DB_HOST; | |
fastcgi_param DB_NAME $$DB_NAME; | |
fastcgi_param DB_USER $$DB_USER; | |
fastcgi_param DB_PASSWORD $$DB_PASSWORD; | |
fastcgi_param WP_SITEURL $$WP_SITEURL; | |
fastcgi_param WP_HOME $$WP_HOME; | |
} | |
}' | envsubst '$$DB_HOST $$DB_NAME $$DB_USER $$DB_PASSWORD $$WP_SITEURL $$WP_HOME' > /etc/nginx/conf.d/default.conf && nginx -g 'daemon off;'" | |
depends_on: | |
- php | |
links: | |
- php | |
php: | |
image: php:7-fpm | |
expose: | |
- '9000' | |
- '9003' | |
volumes: | |
- './:/var/www/html' | |
command: > | |
sh -c 'apt-get update && apt-get install -y mariadb-client zlib1g-dev libzip-dev libxml2-dev git && \ | |
docker-php-ext-install -j$$(nproc) mysqli zip soap && \ | |
pecl install xdebug-3.0.4 && \ | |
docker-php-ext-enable mysqli zip xdebug && \ | |
echo "" >> /usr/local/etc/php/conf.d/xdebug.ini && \ | |
echo "[xdebug]" >> /usr/local/etc/php/conf.d/xdebug.ini && \ | |
echo "zend_extension = /usr/local/lib/php/extensions/no-debug-non-zts-20190902/xdebug.so" >> /usr/local/etc/php/conf.d/xdebug.ini && \ | |
echo "xdebug.mode=debug" >> /usr/local/etc/php/conf.d/xdebug.ini && \ | |
echo "xdebug.start_with_request=yes" >> /usr/local/etc/php/conf.d/xdebug.ini && \ | |
echo "xdebug.start_upon_error=yes" >> /usr/local/etc/php/conf.d/xdebug.ini && \ | |
echo "xdebug.client_host=host.docker.internal" >> /usr/local/etc/php/conf.d/xdebug.ini && \ | |
echo "xdebug.discover_client_host=true" >> /usr/local/etc/php/conf.d/xdebug.ini && \ | |
echo "xdebug.client_port=9003" >> /usr/local/etc/php/conf.d/xdebug.ini && \ | |
php-fpm' | |
depends_on: | |
- database | |
links: | |
- database | |
composer: | |
image: 'composer' | |
volumes: | |
- './:/app' | |
entrypoint: ['composer'] | |
database: | |
image: mysql:5 | |
environment: | |
- MYSQL_ALLOW_EMPTY_PASSWORD='yes' | |
- MYSQL_ROOT_HOST=% | |
- MYSQL_DATABASE=database | |
expose: | |
- '3306' | |
ports: | |
- '3306:3306' | |
volumes: | |
- "database:/var/lib/mysql" | |
- ".:/docker-entrypoint-initdb.d" | |
volumes: | |
database: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment