Docker Wordpress with MariaDB

Docker is an open source tool for running isolated containers. Docker containers wrap up software and its dependencies into a standardized unit for software development that includes everything it needs to run: code, runtime, system tools and libraries.

Docker containers can be a true and efficient productivity booster for building web apps.

Docker builds a container by reading the instructions from a Dockerfile - a text file that contains all commands - in order, needed to build a given image. The same container that the developer builds and tests on his PC can run in production, on VMs, in the cloud and a lot more places

We’ll setup a WordPress & Maria DB development environment using two Docker containers.

Docker Compose is a tool for defining and running multi-container Docker applications. With Compose, you use a YAML file to configure your application’s services. Then, with a single command, you create and start all the services from your configuration.

https://docs.docker.com/compose/

Create the Docker Compose config docker-compose.yml

version: '3.7'

services:
    db:
        image: mariadb:latest
        volumes:
          - data_db:/var/lib/mysql
        restart: always
        environment:
            MYSQL_ROOT_PASSWORD: mypassword
            MYSQL_DATABASE: wordpress
            MYSQL_USER: wordpress
            MYSQL_PASSWORD: wordpress

    wordpress:
        image: wordpress:latest
        build: .
        depends_on:
            - db
        ports:
            - 8080:80
        restart: always
        environment:
            WORDPRESS_DB_HOST: db:3306
            WORDPRESS_DB_USER: wordpress
            WORDPRESS_DB_PASSWORD: wordpress
        volumes:
            - ./config/php.conf.ini:/usr/local/etc/php/conf.d/conf.ini
            - ./wordpress/:/var/www/html/
volumes:
    data_db:

We also want a configuration file to set some php variables config/php.conf

file_uploads = On
memory_limit = 64M
upload_max_filesize = 64M
post_max_size = 64M
max_execution_time = 600

We’re ready to start the environment. We use:

docker-compose up

Docker WordPress Docs https://hub.docker.com/_/wordpress