Skip to content

Instantly share code, notes, and snippets.

@ekandreas
Last active January 29, 2021 00:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ekandreas/3fd4bca29dc0b52257c4216cc25cda7a to your computer and use it in GitHub Desktop.
Save ekandreas/3fd4bca29dc0b52257c4216cc25cda7a to your computer and use it in GitHub Desktop.
Dockerize Roots Bedrock WP w ES
vendor
dist
web/app/mu-plugins/*/
!web/app/mu-plugins/bedrock-autoloader.php
!web/app/mu-plugins/disallow-indexing.php
!web/app/mu-plugins/register-theme-directory.php
web/app/plugins/*/
web/wp
web/app/db.php
web/app/themes/*/node_modules
web/app/themes/*/dist
web/app/themes/*/vendor
web/app/uploads
# placed in docker folder
user 1000;
worker_processes 1;
error_log stderr info;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
log_not_found off;
server_tokens off;
include /etc/mime.types;
server {
listen 8080 default_server;
port_in_redirect off;
root /var/www/web;
index index.php;
rewrite ^/(wp-.*.php)$ /wp/$1 last;
rewrite ^/(wp-(content|admin|includes).*) /wp/$1 last;
if (!-e $request_filename) {
rewrite /wp-admin$ http://$host$request_uri/ permanent;
rewrite ^(/[^/]+)?(/wp-.*) $2 last;
rewrite ^(/[^/]+)?(/.*\.php) $2 last;
}
# Turn off access logs for favicon.ico
location = /favicon.ico {
access_log off;
}
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
include /etc/fastcgi_params;
fastcgi_pass web:9000;
fastcgi_read_timeout 60;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
}
;placed in docker folder
opcache.enable = 1
opcache.revalidate_freq = 0
;opcache.validate_timestamps = 0
opcache.interned_strings_buffer = 16
opcache.max_accelerated_files = 7000
opcache.memory_consumption = 128
opcache.fast_shutdown = 1
opcache.file_cache = /var/tmp/php/opcache
opcache.file_cache_consistency_checks = 1
upload_max_filesize = 100M
post_max_size = 100M
expose_php = Off
memory_limit = 64M
max_execution_time = 10
error_reporting = E_ALL & ~E_NOTICE & ~E_WARNING & ~E_STRICT & ~E_DEPRECATED
display_startup_errors = on
error_log = /proc/self/fd/2
log_errors = on
[global]
daemonize = no
error_log = /proc/self/fd/2
[www]
user = 1000
group = 1000
listen = 9000
access.log = /proc/self/fd/2
catch_workers_output = yes
pm = static
pm.max_children = 10
pm.max_requests = 500
pm.status_path = /status
ping.path = /ping
ping.response = pong
save ""
appendonly no
maxmemory-policy allkeys-lru
maxmemory 64mb
protected-mode no
version: '3'
services:
composer:
build:
context: .
dockerfile: docker/Dockerfile.composer
phpmyadmin:
image: phpmyadmin/phpmyadmin
ports:
- "8081:80"
environment:
PMA_HOST: mysql
depends_on:
- mysql
mysql:
image: mysql:5.7
volumes:
- ./.data/db:/var/lib/mysql
ports:
- "3306:3306"
command: --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci --sql-mode="STRICT_TRANS_TABLES"
environment:
MYSQL_DATABASE: wordpress
MYSQL_USER: mysql
MYSQL_PASSWORD: password
MYSQL_ROOT_PASSWORD: password
redis:
user: "1000:1000"
image: redis:4
ports:
- "6379:6379"
command: ["redis-server", "/usr/local/etc/redis/redis.conf"]
volumes:
- ./docker/development-redis.conf:/usr/local/etc/redis/redis.conf
web:
user: "1000:1000"
build:
context: .
dockerfile: docker/Dockerfile.web
args:
BUILDER_COMPOSER: elseif_composer
ports:
- "9000:9000"
environment:
DB_NAME: wordpress
DB_USER: mysql
DB_PASSWORD: password
DB_HOST: mysql
DB_PREFIX: wp_
WP_ENV: development
WP_HOME: http://local.elseif.se
WP_SITEURL: http://local.elseif.se
EP_HOST: http://elasticsearch:9200
volumes:
- ./web:/var/www/web
- ./config:/var/www/config
- ./vendor:/var/www/vendor
- ./docker/development-php.ini:/usr/local/etc/php/php.ini
- ./docker/development-phpfpm.conf:/usr/local/etc/php-fpm.d/zz-docker.conf
nginx:
user: "1000:1000"
build:
context: .
dockerfile: docker/Dockerfile.nginx
args:
BUILDER_COMPOSER: elseif_composer
depends_on:
- redis
- mysql
- web
ports:
- "80:8080"
volumes:
- ./web:/var/www/web
- ./docker/development-nginx.conf:/etc/nginx/nginx.conf
elasticsearch:
user: "1000"
image: docker.elastic.co/elasticsearch/elasticsearch-oss:6.2.4
environment:
- discovery.type=single-node
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms512m -Xmx512m -Des.enforce.bootstrap.checks=true"
ulimits:
memlock:
soft: -1
hard: -1
volumes:
- ./.esdata:/usr/share/elasticsearch/data
ports:
- 9200:9200
FROM composer:1.8.4 AS composer
COPY composer.json /app/composer.json
COPY composer.lock /app/composer.lock
RUN mkdir -p /app/web/app/mu-plugins
RUN mkdir -p /app/web/app/plugins
RUN mkdir -p /app/web/wp
RUN composer install --working-dir=/app
ARG BUILDER_COMPOSER=composer
FROM ${BUILDER_COMPOSER} as composer
FROM nginx:1.15.12-alpine
RUN rm -rf /etc/nginx/nginx.conf
COPY /web /var/www/web
RUN mv /etc/nginx/mime.types /etc/mime.types
RUN mv /etc/nginx/fastcgi_params /etc/fastcgi_params
# Composer installed dependencies and plugins
COPY --from=composer /app/web/app/mu-plugins /var/www/web/app/mu-plugins
COPY --from=composer /app/web/app/plugins /var/www/web/app/plugins
COPY --from=composer /app/web/wp /var/www/web/wp
WORKDIR /var/www/web
# Make container run as non-root (docker friendly)
RUN mkdir -p /var/log/nginx
RUN mkdir -p /var/cache/nginx
RUN touch /var/run/nginx.pid && \
chown 1000:1000 /var/run/nginx.pid && \
chown -R 1000:1000 /var/cache/nginx && \
chown -R 1000:1000 /var/log/nginx && \
chmod -R 777 /var/log/nginx /var/cache/nginx
USER 1000:1000
EXPOSE 8080
ARG BUILDER_COMPOSER=composer
FROM ${BUILDER_COMPOSER} as composer
FROM php:7.3-fpm
RUN apt-get update \
&& echo "postfix postfix/mailname string example.com" | debconf-set-selections \
&& echo "postfix postfix/main_mailer_type string 'Internet Site'" | debconf-set-selections \
&& apt-get install -y \
libfreetype6-dev \
libjpeg62-turbo-dev \
libpng-dev \
libz-dev \
gnupg2 \
postfix \
mysql-client \
less \
&& docker-php-ext-install -j$(nproc) \
mysqli \
pdo \
pdo_mysql \
&& docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
&& docker-php-ext-install -j$(nproc) gd \
&& docker-php-ext-configure opcache --enable-opcache --enable-opcache-file \
&& docker-php-ext-install opcache \
&& pecl install redis \
&& docker-php-ext-enable redis \
&& apt-get remove -y build-essential libz-dev \
&& apt-get autoremove -y \
&& apt-get clean
RUN curl https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar > wp-cli.phar \
&& chmod +x wp-cli.phar \
&& mv wp-cli.phar /usr/local/bin/wp
COPY /web /var/www/web
COPY /config /var/www/config
# Composer installed dependencies and plugins
COPY --from=composer /app/vendor /var/www/vendor
COPY --from=composer /app/web/app/mu-plugins /var/www/web/app/mu-plugins
COPY --from=composer /app/web/app/plugins /var/www/web/app/plugins
COPY --from=composer /app/web/wp /var/www/web/wp
WORKDIR /var/www/web
USER 1000:1000
RUN mkdir -p /var/tmp/php/opcache
EXPOSE 9000
CMD ["php-fpm"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment