This article is published under a SIGNATURE 4.0 International (CC BY 4.0) license. Signature 4.0 International (CC BY 4.0)

Author: Su Yang

Creation time: April 7, 2019 statistical word count: 4925 words reading time: 10 minutes to read this article links: soulteary.com/2019/04/07/…


Build WordPress with Docker and Traefik

In fact, I have wanted to revisit WordPress for more than one time. However, due to the amount of custom code, many articles had to be shelved in the draft box. Just in time for the holiday, organize the draft box and start talking about building it.

This article will use Docker, Compose, Traefik to build WordPress. The complete operation should take less than 10 minutes.

Why WordPress

Whenever we talk about CMS software and rich community resources, we can’t help but think of a “cure-all” : WordPress. Official data says:

Over 60 million people have chosen WordPress to power the place on the web they call “home”

Hundreds of thousands of developers, content creators, and site owners gather at monthly meetups in 436 cities worldwide.

WordPress supports 33% of the Internet.

Many people still remember it as a blogging system with slow execution, poor security and bloated code. But in fact, after more than a decade of iterations, it’s now 5.0 (and 7.0 for the mainstream PHP runtime), where performance is no longer an issue, and security issues can be eliminated with the right safeguards.

Emmm, the code is still pretty bloated.

Based on official mirror

The container image can be downloaded by using the following command:

docker pull wordpress
Copy the code

But for better configuration use, we use compose to compose and save the following as docker-comemess.yml:

version: '3'

services:

  wp:
    image: ${WP_IMAGE}
    restart: always
    networks:
      - traefik
    environment:
        WORDPRESS_DB_HOST: ${DB_HOST}
        WORDPRESS_TABLE_PREFIX: ${WP_DB_PREFIX}
        WORDPRESS_DB_NAME: ${DB_NAME}
        WORDPRESS_DB_USER: ${DB_USER}
        WORDPRESS_DB_PASSWORD: ${DB_PASS}
    volumes:
    # If you need to customize the upload file size
    # - ./config/php.conf.uploads.ini:/usr/local/etc/php/conf.d/uploads.ini
      - ./wp-app:/var/www/html
    labels:
      - "traefik.enable=true"
      - "traefik.frontend.rule=Host:${WP_DOMAINS}"
      - "traefik.frontend.entryPoints=https,http"

  mariadb:
    image: ${DB_IMAGE}
    restart: always
    container_name: ${DB_HOST}
    networks:
      - traefik
    environment:
      MYSQL_DATABASE: ${DB_NAME}
      MYSQL_USER: ${DB_USER}
      MYSQL_PASSWORD: ${DB_PASS}
      MYSQL_ROOT_PASSWORD: ${DB_ROOT_PASS}
    volumes:
      - ./data:/var/lib/mysql

  pma:
    image: ${PMA_IMAGE}
    restart: always
    networks:
      - traefik
    environment:
      MYSQL_USER: ${DB_USER}
      MYSQL_PASSWORD: ${DB_PASS}
      MYSQL_ROOT_PASSWORD: ${DB_ROOT_PASS}
      PMA_HOST: ${DB_HOST}
    labels:
      - "traefik.enable=true"
      - "traefik.frontend.rule=Host:${PMA_DOMAIN}"

networks:
  traefik:
    external: true
Copy the code

If you don’t know how to use Traefik, check out my previous post. I won’t go into too much detail here.

For maintainability, we abstracted container image version information, application domain name, database configuration, etc. into a separate environment configuration file. Env.

WP_IMAGE = wordpress: 5.1.1 php7.3 - apache WP_DOMAINS=wp.lab.com, wp. Lab. IO WP_DB_PREFIX = wp DB_IMAGE = mariadb: 10.3.8 DB_HOST=wp-db DB_NAME=wordpress DB_USER=wordpress DB_PASS=wordpress DB_ROOT_PASS=soulteary PMA_IMAGE = phpmyadmin/phpmyadmin: 4.8.2 PMA_DOMAIN=pma.wp.lab.com, pma. Wp. Lab. IOCopy the code

When both files are saved, execute the docker-compose up command and you’ll see a lot of logs. When you see something like the following, your WordPress environment is ready.

wp-db      |
wp-db      | MySQL init process done. Ready forStart up. The wp - db | wp - 2019-04-06 db | 16:26:48 0 [Note] mysqld (mysqld 10.3.8 - MariaDB - 1:10. 3.8 + maria to Jessie) starting the as process 1 ... wp-db | 2019-04-06 16:26:48 0 [Note] InnoDB: Using Linux native AIO wp-db | 2019-04-06 16:26:48 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins wp-db | 2019-04-06 16:26:48 0 [Note] InnoDB: Uses event mutexes wp-db | 2019-04-06 16:26:48 0 [Note] InnoDB: Compressed tables use zlib 1.2.8 wp - 2019-04-06 db | 16:26:48 0 [Note] InnoDB: Number of pools: 1 wp-db | 2019-04-06 16:26:48 0 [Note] InnoDB: Using SSE2 crc32 instructions wp-db | 2019-04-06 16:26:48 0 [Note] InnoDB: Initializing buffer pool, total size = 256M, instances = 1, chunk size = 128M wp-db | 2019-04-06 16:26:48 0 [Note] InnoDB: Completed initialization of buffer pool wp-db | 2019-04-06 16:26:48 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority(). wp-db | 2019-04-06 16:26:48 0 [Note] InnoDB: 128 out of 128 rollback segments are active. wp-db | 2019-04-06 16:26:48 0 [Note] InnoDB: Creating shared tablespacefor temporary tables
wp-db      | 2019-04-06 16:26:48 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait. wp-db | 2019-04-06 16:26:48 0 [Note] InnoDB: File'./ibtmp1'Size is now 12 MB. Wp - 2019-04-06 db | 16:26:48 0 [Note] InnoDB: 10.3.8 started;log sequence number 1630833; transaction id 21
wp-db      | 2019-04-06 16:26:48 0 [Note] Plugin 'FEEDBACK' is disabled.
wp-db      | 2019-04-06 16:26:48 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
wp-db      | 2019-04-06 16:26:48 0 [Note] Server socket created on IP: '... '.
wp-db      | 2019-04-06 16:26:48 0 [Note] InnoDB: Buffer pool(s) load completed at 190406 16:26:48
wp-db      | 2019-04-06 16:26:48 0 [Warning] 'proxies_priv' entry '@% root@e97787886b74' ignored in --skip-name-resolve mode.
wp-db      | 2019-04-06 16:26:48 0 [Note] Reading of all Master_info entries succeded
wp-db      | 2019-04-06 16:26:48 0 [Note] Added new Master_info ' ' to hash table
wp-db      | 2019-04-06 16:26:48 0 [Note] mysqld: ready for connections.
wp-db      | Version: '10.3.8 - MariaDB - 1:10. 3.8 + maria to Jessie'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  mariadb.org binary distribution
wp_1       | AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.23.0.8. Set the 'ServerName' directive globally to suppress this message
Copy the code

At this point, launch the browser, open the domain name (WP_DOMAIN) configured in our configuration file, and begin the famous “three minute” installation.

Fill in the appropriate information, go Next, and WordPress is installed.

This is followed by specific application configuration, as well as performance and security optimization.

other

If you need to operate a database, but don’t want to download the database tool or use the command line, you can use PHPMyAdmin **, again, open the PMA_DOMAIN from the configuration file in your browser.

Note, however, that you need to log in using root and root password because Mariadb does not authorize remote access to other user accounts by default.

The last

As the first post on WordPress, it will look a little simpler, but if you’ll excuse me, the next post will build on this and expand on the details of containerized deployment.


I now have a small toss group, which gathered some like to toss small partners.

In the case of no advertisement, we will talk about software, HomeLab and some programming problems together, and also share some technical salon information in the group from time to time.

Like to toss small partners welcome to scan code to add friends. (Please specify source and purpose, otherwise it will not be approved)

All this stuff about getting into groups