Docker: Wordpress with Nginx - PHP-FPM -MariaDB


2 min read

I've created a docker-compose file to run a wordpress stack based on:
Nginx with PHP-fpm and MariaDB.

In the image I change the max_upload to 40MB.

I'm using the latest wordpress:fpm image to build it.
The dockerfile is included on my Github.

I'm using Traefik to expose the nginx container to the outside.
(my network for that is called: Proxy)

The stack below uses my wordpress image.
If you want to create it yourself then:
-clone the repo
-change the lines in dockerfile ( for the wordpress container) to:

    wordpress:
build: ..
#image: back2basic/wordpress
volumes: - ./wordpress:/var/www/html

if you choose to run my image then clone the repo and bring up the stack. ( image is build for x86)

Here the stack to run in docker-compose:

version: '3.6'

networks: 
    Backend:
        internal: true
    Proxy:
        external: true

services:
    mysql:
        image: mariadb
        volumes:
            - ./db-data:/var/lib/mysql
            - ./backup:/backupData
        environment:
            MYSQL_ROOT_PASSWORD: wordpress
        ports:
            - 3306
        networks: 
            - Backend
        deploy:
            replicas: 1
            placement:
                constraints:
                    - node.role != manager
            update_config:
                parallelism: 1
                delay: 30s
                order: start-first
            
    phpmyadmin:
        image: phpmyadmin/phpmyadmin
        environment:
            PMA_HOST: mysql
        ports:
            - 80
        networks: 
            - Backend
            - Proxy
        deploy:
            replicas: 0
            placement:
                constraints:
                    - node.role != manager
            update_config:
                parallelism: 1
                delay: 30s
                order: start-first
            labels:
                traefik.port: 80
                traefik.frontend.rule: "Host:php.proxy.example.com"
                traefik.docker.network: "Proxy"

    wordpress:
        #build: ..
        image: back2basic/wordpress  
        volumes:
            - ./wordpress:/var/www/html
        environment:
            WORDPRESS_DB_NAME: wordpress
            WORDPRESS_TABLE_PREFIX: wp_
            WORDPRESS_DB_HOST: wordpress
            WORDPRESS_DB_USER: wordpress
            WORDPRESS_DB_PASSWORD: wordpress
        links:
            - mysql
        ports:
            - 9000
        networks: 
            - Backend
        deploy:
            replicas: 1
            placement:
                constraints:
                    - node.role != manager
            update_config:
                parallelism: 1
                delay: 30s
                order: start-first

    nginx:
        image: nginx:latest
        ports:
            - 80
        volumes:
            - ../nginx.conf:/etc/nginx/nginx.conf
            - ./nginx:/etc/nginx/conf.d
            - ./logs/nginx:/var/log/nginx
            - ./wordpress:/var/www/html
        links:
            - wordpress
        networks:
            - Backend
            - Proxy
        deploy:
            replicas: 1
            placement:
                constraints:
                    - node.role != manager
            update_config:
                parallelism: 1
                delay: 30s
                order: start-first
            labels:
                traefik.port: 80
                traefik.frontend.rule: "Host:www.example.com,example.com"
                traefik.docker.network: "Proxy"
        healthcheck:
            test: ["CMD", "curl", "-f", "http://localhost"]
            interval: 1m30s
            timeout: 10s
            retries: 5
            start_period: 15s

Link to the repo: https://github.com/back2basic/wordpress.git