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

How to remove the header from the element table

Document hints using the show-header attribute sh...

Detailed explanation of the installation and use of Vue-Router

Table of contents Install Basic configuration of ...

Simple use of Vue bus

Simple use of Vue bus Scenario description: Compo...

Vue + element to dynamically display background data to options

need: Implement dynamic display of option values ...

Example analysis to fix problems in historical Linux images

Fix for issues with historical Linux images The E...

How to disable web page styles using Firefox's web developer

Prerequisite: The web developer plugin has been in...

Dynamically edit data in Layui table row

Table of contents Preface Style Function Descript...

HTML web page creation tutorial Use iframe tags carefully

Using iframes can easily call pages from other we...

Detailed explanation of the basic use of centos7 firewall in linux

1. Basic use of firewalld start up: systemctl sta...

How to set the width attribute to the style of the span tag

If you directly set the width attribute to the sty...

JavaScript functional programming basics

Table of contents 1. Introduction 2. What is func...

Commonly used HTML format tags_Powernode Java Academy

1. Title HTML defines six <h> tags: <h1&...

CSS solves the misalignment problem of inline-block

No more nonsense, post code HTML part <div cla...

One minute to experience the smoothness of html+vue+element-ui

Technology Fan html web page, you must know vue f...

Detailed explanation of the use of the <meta> tag in HTML

In the web pages we make, if we want more people ...