Table of Contents
Cause
Purchasing a host
Initialize the docker environment
Write docker-compose
Configuration overview
Configuration analysis
caddy
db
app
Use docker stack to deploy
Home CMS Tutorial WordPress How to use Docker Swarm to build WordPress

How to use Docker Swarm to build WordPress

Apr 20, 2021 pm 02:14 PM
docker php wordpress

The following tutorial column of WordPress will introduce to you how to use Docker Swarm to build WordPress. I hope it will be helpful to friends in need!

How to use Docker Swarm to build WordPress

Cause

I once built wordpress on Vultr , but due to well-known reasons, access to this place is getting slower and slower. Later, I chose Sina Cloud. Sina Cloud is indeed cheap and very good, but it requires registration and the comment function may need to be castrated. After thinking about it, I might as well forget it and just find a Hong Kong host to build wordpress.

Purchasing a host

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

The configuration is as shown below
How to use Docker Swarm to build WordPress

Initialize the docker environment

Although there is a function to install wordpress , but I don’t recommend it because the configuration is too old

In the end I chose theubuntu18.04 system. You can install docker and initialize it directly by using the following commanddocker swarm

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

Write 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
Copy after login

Configuration analysis

caddy

It is used as a reverse proxy and takes 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:9000 php
    rewrite {
        if {path} not_match ^\/wp-admin
        to {path} {path}/ /index.php?_url={uri}
    }
    log stdout
    errors stderr
}
Copy after login

Here I used the config function of docker swarm and wrote the configuration directly towp_caddy in this configuration.

db

Mysql8 is used here, which is supported by wordpress, and the performance should be better.
It should be noted that commmand must be added command: --default-authentication-plugin=mysql_native_password Otherwise, there is no way to perform password authentication. I just forgot to add this and it hurt for a while.

app

Pay attention to the connection method
If you deploy it using docker stack, what is the name of the deployment? The name prefix must be added to the database connection. . For example, here is 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, it must be changed to wordpress_db accordingly.

Pay attention to configuring volume
- wordpress:/var/www/html This thing must be configured. I didn’t configure this thing last time, so I deleted it. container, the theme is gone.

Use docker stack to deploy

One line commanddocker stack deploy -c docker-compose.yml wpYou can enter wordpress after a while

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

The above is the detailed content of How to use Docker Swarm to build WordPress. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1666
14
PHP Tutorial
1272
29
C# Tutorial
1252
24
How to build a website for wordpress host How to build a website for wordpress host Apr 20, 2025 am 11:12 AM

To build a website using WordPress hosting, you need to: select a reliable hosting provider. Buy a domain name. Set up a WordPress hosting account. Select a topic. Add pages and articles. Install the plug-in. Customize your website. Publish your website.

How do containerization technologies (like Docker) affect the importance of Java's platform independence? How do containerization technologies (like Docker) affect the importance of Java's platform independence? Apr 22, 2025 pm 06:49 PM

Containerization technologies such as Docker enhance rather than replace Java's platform independence. 1) Ensure consistency across environments, 2) Manage dependencies, including specific JVM versions, 3) Simplify the deployment process to make Java applications more adaptable and manageable.

Docker on Linux: Containerization for Linux Systems Docker on Linux: Containerization for Linux Systems Apr 22, 2025 am 12:03 AM

Docker is important on Linux because Linux is its native platform that provides rich tools and community support. 1. Install Docker: Use sudoapt-getupdate and sudoapt-getinstalldocker-cedocker-ce-clicotainerd.io. 2. Create and manage containers: Use dockerrun commands, such as dockerrun-d--namemynginx-p80:80nginx. 3. Write Dockerfile: Optimize the image size and use multi-stage construction. 4. Optimization and debugging: Use dockerlogs and dockerex

The Compatibility of IIS and PHP: A Deep Dive The Compatibility of IIS and PHP: A Deep Dive Apr 22, 2025 am 12:01 AM

IIS and PHP are compatible and are implemented through FastCGI. 1.IIS forwards the .php file request to the FastCGI module through the configuration file. 2. The FastCGI module starts the PHP process to process requests to improve performance and stability. 3. In actual applications, you need to pay attention to configuration details, error debugging and performance optimization.

How to import the source code of wordpress How to import the source code of wordpress Apr 20, 2025 am 11:24 AM

Importing WordPress source code requires the following steps: Create a sub-theme for theme modification. Import the source code and overwrite the files in the sub-topic. Activate the sub-theme to make it effective. Test the changes to make sure everything works.

What happens if session_start() is called multiple times? What happens if session_start() is called multiple times? Apr 25, 2025 am 12:06 AM

Multiple calls to session_start() will result in warning messages and possible data overwrites. 1) PHP will issue a warning, prompting that the session has been started. 2) It may cause unexpected overwriting of session data. 3) Use session_status() to check the session status to avoid repeated calls.

How to write a header of a wordpress How to write a header of a wordpress Apr 20, 2025 pm 12:09 PM

The steps to create a custom header in WordPress are as follows: Edit the theme file "header.php". Add your website name and description. Create a navigation menu. Add a search bar. Save changes and view your custom header.

How to register a wordpress account How to register a wordpress account Apr 20, 2025 am 11:45 AM

To create an account on WordPress, simply visit its website, select the registration option, fill in the registration form, and verify your email address. Other ways to register include using a Google account or Apple ID. The benefits of signing up include creating a website, gaining features, joining the community, and gaining support.

See all articles