本文最后更新于 2024年5月16日。
yml文件`wordpress-docker-compose.yml
version: "3.7"
services:
wordpress:
image: wordpress
restart: always
# ports:
# - 8080:80
environment:
WORDPRESS_DB_HOST: mariadb #这里的数据库用的时lnmp中的,在同一个网络
WORDPRESS_DB_USER: root
WORDPRESS_DB_PASSWORD: SQLroot77
WORDPRESS_DB_NAME: wordpress
volumes:
- wordpress:/var/www/html
labels:
- "traefik.enable=true"
- "traefik.http.routers.wordpress.entrypoints=websecure"
- "traefik.http.routers.wordpress.rule=Host(`wp.weiyoun.com`)"
- "traefik.http.routers.wordpress.tls.certresolver=lets-encr"
volumes:
wordpress:
networks:
default:
external:
name: traefik
运行
docker-compose -f wordpress-docker-compose.yml up
用域名访问,提示数据库连接错误
这是因为数据库中没有创建wordpress
数据库
进入数据库容器docker exec -it dc1_mariadb_1 bash 进入数据库
mysql -u root -p
创建并查询数据库
MariaDB [(none)]> create database wordpress;
Query OK, 1 row affected (0.000 sec)
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| user |
| wordpress |
| zblog |
+--------------------+
6 rows in set (0.000 sec)
再次用域名访问,成功进入安装界面