Featured image of post Docker-Compose部署Wordpress

Docker-Compose部署Wordpress

推荐文章:

【合集】Docker

创建挂载目录

注意:若挂载的为文件夹,则不需要,在执行命令时会自动创建,但是要是挂载文件,必须要提前准备

1
2
3
4
5
6
7
8
9
mkdir -p ~/nginx/data
mkdir -p ~/nginx/config/conf.d
mkdir -p ~/nginx/logs
mkdir -p ~/nginx/ssl
touch ~/nginx/config/nginx.conf
touch ~/nginx/config/conf.d/default.conf

mkdir -p ~/wordpress/html
mkdir -p ~/mysql

wordpress目录下添加

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
version: '3'
services:
  mysql:
    image: mysql
    container_name: mysql
    ports:
      - '3306:3306'
    volumes:
      - ./mysql:/var/lib/mysql
    environment:
      - MYSQL_ROOT_PASSWORD=数据库密码
      - MYSQL_DATABASE=wordpress
      - MYSQL_USER=wordpress
      - MYSQL_PASSWORD=数据库密码
    networks:
      - backend
    restart: always

  wordpress:
    depends_on:
      - mysql
    image: wordpress
    container_name: wordpress
    ports:
      - '9000:80'
    volumes:
      - ./wordpress/html:/var/www/html
    environment:
      - WORDPRESS_DB_NAME=wordpress
      - WORDPRESS_TABLE_PREFIX=wp_
      - WORDPRESS_DB_HOST=mysql:3306
      - WORDPRESS_DB_USER=wordpress
      - WORDPRESS_DB_PASSWORD=数据库密码
    links:
      - mysql
    networks:
      - backend
      - frontend
    restart: always

  nginx:
    image: nginx
    container_name: nginx
    ports:
      - '80:80'
      - "443:443"
    volumes:
      - ./nginx/data:/usr/share/nginx/html
      - ./nginx/config/nginx.conf:/etc/nginx/nginx.conf
      - ./nginx/config/conf.d/default.conf:/etc/nginx/conf.d/default.conf
      - ./nginx/logs:/var/log/nginx
      - ./nginx/ssl:/ssl
      - /var/run/docker.sock:/tmp/docker.sock:ro
    links:
      - wordpress
    networks:
      - frontend
    restart: always

networks:
  frontend:
    #name: test_frontend
    driver: bridge
  backend:
    #name: test_backend
    driver: bridge

nginx目录下添加 nginx.conf

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#运行nginx的用户
user  nginx;
#启动进程设置成和CPU数量相等
worker_processes  1;

#全局错误日志及PID文件的位置
error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;

#工作模式及连接数上限
events {
#单个后台work进程最大并发数设置为1024
worker_connections  1024;
}


http {
#设定mime类型
include       /etc/nginx/mime.types;
default_type  application/octet-stream;

#设定日志格式
 log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                   '$status $body_bytes_sent "$http_referer" '
                   '"$http_user_agent" "$http_x_forwarded_for"';

 access_log  /var/log/nginx/access.log  main;

 sendfile        on;
 #tcp_nopush     on;

     #设置连接超时的事件
 keepalive_timeout  65;

     #开启GZIP压缩
 #gzip  on;

 include /etc/nginx/conf.d/*.conf;
}

wpress目录,docker-compose up -d

docker ps 查看容器

配置https 考文章:SSL 证书 Nginx 服务器 SSL 证书安装部署 - 证书安装 - 文档中心 - 腾讯云 https://cloud.tencent.com/document/product/400/35244

打开地址安装:https://www.zhangxin.cloud/wp-admin/setup-config.php

后台管理地址 https://www.zhangxin.cloud/wp-admin/

皖ICP备2024056275号-1
发表了78篇文章 · 总计149.56k字
本站已稳定运行