Skip to content

Instantly share code, notes, and snippets.

@kormat
Last active December 16, 2018 13:14
Show Gist options
  • Save kormat/94a340aaf47d5b1165ef0c9a16c1f34d to your computer and use it in GitHub Desktop.
Save kormat/94a340aaf47d5b1165ef0c9a16c1f34d to your computer and use it in GitHub Desktop.
wordpress with php-fpm in docker

This is how to run the wordpress fpm docker image using nginx and mariadb on the host, and with ssmtp to act as the container's MTA. This is the directory layout used:

/etc/wordpress
├── docker-compose.yml
├── image
│   ├── Dockerfile
│   ├── ssmtp.conf
└── secrets
    └── mysql-passwd
/srv/blogs.example.net

See https://medium.com/@kormat/running-wordpress-in-docker-3606fc5a8c4 for more details.

version: '3.1'
services:
wordpress:
build: ./image
container_name: wordpress
image: wordpress-ssmtp
restart: always
network_mode: bridge
volumes:
- /etc/wordpress/secrets:/mnt/secrets
- /srv/blogs.example.net:/var/www/html
- /var/run/mysqld:/var/run/mysqld
ports:
- 127.0.0.1:9000:9000
environment:
WORDPRESS_DB_HOST: localhost:/var/run/mysqld/mysqld.sock
WORDPRESS_DB_NAME: blogs
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD_FILE: /mnt/secrets/mysql-passwd
cap_drop:
- ALL
cap_add:
- CHOWN
- FOWNER
- SETGID
- SETUID
FROM wordpress:5.0.0-fpm-alpine
RUN apk add --no-cache ssmtp
COPY ssmtp.conf /etc/ssmtp/ssmtp.conf
RUN echo 'sendmail_path = "/usr/sbin/ssmtp -t -i"' > /usr/local/etc/php/conf.d/mail.ini
server {
server_name blogs.example.net;
root /srv/blogs.example.net;
index index.php;
location / {
try_files $uri $uri/ /index.php?$args;
}
# Uncomment after install is finished.
#rewrite /wp-admin$ $scheme://$host$uri/ permanent;
location ~ [^/]\.php(/|$) {
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
if (!-f $document_root$fastcgi_script_name) {
return 404;
}
# Mitigate https://httpoxy.org/ vulnerabilities
fastcgi_param HTTP_PROXY "";
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME /var/www/html$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED /var/www/html$fastcgi_path_info;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment