How to use Docker Swarm to build WordPress

How to use Docker Swarm to build WordPress

cause

I once set up WordPress on Vultr, but for well-known reasons, the access to this place became slower and slower. Later, I chose Sina Cloud. Sina Cloud is indeed cheap and good, but it requires registration and the comment function is probably going to be removed. After thinking about it, I decided to give up and just find a host in Hong Kong to build WordPress.

Buy Hosting

I have chosen Alibaba Cloud's lightweight application server. The advantage of this host is that it is cheap and sufficient.
For example, the host in Hong Kong that I chose only costs 24 dollars a month, with one core and one GB of memory, a network speed of 30Mbps, 25GB of disk space, and 1TB of monthly traffic.

The configuration is as follows

Initialize the Docker environment

Although there is a function to install wordpress above, I don’t recommend it because the configuration is too old. In the end, I chose the Ubuntu 18.04 system. I can install docker and initialize docker swarm directly with the following command:

curl -o- -L https://gist.githubusercontent.com/hangox/e679464f35dc2a78920e6249a21d7958/raw/c5541e38979dca1e3e1e9704ad171ed2f0556fa1/ubunut-install-docker.sh | bash

Writing docker-compose

Configuration Overview

version: '3.7'

services:
 caddy:
  image: abiosoft/caddy
  ports:
   - 80:80
   -443:443
  environment:
   - ACME_AGREE=true
   - TZ=Asia/Shanghai
  volumes:
   - caddy:/root/.caddy
   - wp-src:/usr/src/wordpress
  configs:
   - source: wp_caddy
    target: /etc/Caddyfile
 app:
  image: wordpress:5.4.1-php7.2-fpm
  environment:
   TZ: Asia/Shanghai
   WORDPRESS_DB_HOST: wp_db:3306
   WORDPRESS_DB_USER: root
   WORDPRESS_DB_PASSWORD: yourpassword
   WORDPRESS_DB_NAME: wordpress
  depends_on:
   -db
  volumes:
   - wordpress:/var/www/html
   - wp-src:/usr/src/wordpress
 db:
  image:mysql:8
  environment:
   TZ: Asia/Shanghai
   MYSQL_ROOT_PASSWORD: yourpassword
   MYSQL_DATABASE: wordpress
  command: --default-authentication-plugin=mysql_native_password
  volumes:
   -db:/var/lib/mysql

volumes:
 wordpress:
 db:
 caddy:
 wp-src:
configs:
 wp_caddy:
  external: true

Configuration parsing

caddy

Used as a reverse proxy, while taking into account https certificate application, the configuration is as follows

https://47log.com https://www.47log.com
  root /usr/src/wordpress
  gzip
  fastcgi/wp_app:9000php
  rewrite {
    if {path} not_match ^\/wp-admin
    to {path} {path}/ /index.php?_url={uri}
  }
  log stdout
  errors stderr
}

Here I used the config function of docker swarm and wrote the configuration directly into the wp_caddy configuration.

db

MySQL8 is used here, which is supported by wordpress and has better performance. It should be noted that the command must be added with command: --default-authentication-plugin=mysql_native_password, otherwise password authentication will not be possible. I just forgot to add this and it was a pain for a while.

app

Pay attention to the connection method. If you are deploying with docker stack, you need to add a prefix to the name of the deployment. For example, here I use docker stack deploy -c docker-compose.yml wp, and the host of my database in the docker network is wp_db. If your stack name is wordpress, you should change it to wordpress_db accordingly.

Note: Configure volume
- wordpress:/var/www/html This thing must be configured. Last time I didn’t configure this thing. I deleted the container and the theme disappeared.

Deploy using docker stack

One line of command docker stack deploy -c docker-compose.yml wp Wait for a while and you can enter WordPress

Why use docker swarm. Because of portainer, docker-swarm can have full-featured configuration capabilities after being connected to portainer.

This is the end of this article about how to use Docker Swarm to build WordPress. For more information about how to use Docker Swarm to build WordPress, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Analysis of the use and principle of Docker Swarm cluster management
  • Example of using Docker Swarm to build a distributed crawler cluster
  • How to use Docker Swarm to build a cluster
  • Detailed explanation of using Docker 1.12 to build a multi-host Docker swarm cluster
  • How to install Docker and use it in Docker Swarm mode
  • Docker swarm simple tutorial

<<:  WiFi Development | Introduction to WiFi Wireless Technology

>>:  Native JS realizes compound motion of various motions

Recommend

jQuery implements navigation bar effect with expansion animation

I designed and customized a navigation bar with a...

HTML page jump passing parameter problem

The effect is as follows: a page After clicking t...

Examples of using provide and inject in Vue2.0/3.0

Table of contents 1. What is the use of provide/i...

A very detailed explanation of Linux C++ multi-thread synchronization

Table of contents 1. Mutex 1. Initialization of m...

Sharing experience on MySQL slave maintenance

Preface: MySQL master-slave architecture should b...

jQuery implements the function of adding and deleting employee information

This article shares the specific code of jQuery t...

MySQL optimization tutorial: large paging query

Table of contents background LIMIT Optimization O...

Theory: The two years of user experience

<br />It has been no more than two years sin...

Standard summary for analyzing the performance of a SQL statement

This article will introduce how to use explain to...

Comparison of the advantages of vue3 and vue2

Table of contents Advantage 1: Optimization of di...

MySQL replication mechanism principle explanation

Background Replication is a complete copy of data...

Specific use of lazy loading and preloading in js

Delayed loading (lazy loading) and preloading are...