一、创建目录
mkdir -p /home/qigx/halo/halo2
mkdir -p /home/qigx/halo/mysql
mkdir -p /home/qigx/halo/mysqlBackup
mkdir -p /home/qigx/firefly/upload
由于docker-compose容器共用一个mysql,启动的时候无法创建多个database,需要创建firefly的sql脚本,当mysql启动初始化的时候运行脚本创建firefly的database
mkdir -p /home/qigx/firefly/sql
echo "create database firefly;" > /home/qigx/firefly/sql/db.sql
二、编写docker-compose.yaml
cd /home/qigx/halo
vim docker-compose.yaml
version: "3"
services:
halo:
image: halohub/halo:2.4.0
container_name: halo
restart: on-failure:3
depends_on:
mysql:
condition: service_healthy
networks:
qgxnetwork:
ipv4_address: 172.18.0.3
volumes:
- /home/qigx/halo/halo2:/root/.halo2
ports:
- "8090:8090"
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8090/actuator/health/readiness"]
interval: 30s
timeout: 5s
retries: 5
start_period: 30s
command:
- --spring.r2dbc.url=r2dbc:pool:mysql://mysql:3306/halo
- --spring.r2dbc.username=root
# MySQL 的密码,请保证与下方 MYSQL_ROOT_PASSWORD 的变量值一致。
- --spring.r2dbc.password=123456
- --spring.sql.init.platform=mysql
# 外部访问地址,请根据实际需要修改
- --halo.external-url=http://www.qigx.vip:1314/
# 初始化的超级管理员用户名
- --halo.security.initializer.superadminusername=admin
# 初始化的超级管理员密码
- --halo.security.initializer.superadminpassword=123456
firefly:
image: fireflyiii/core:latest
container_name: firefly
restart: on-failure:3
depends_on:
- mysql
networks:
qgxnetwork:
ipv4_address: 172.18.0.4
volumes:
- /home/qigx/upload:/var/www/html/storage/upload
ports:
- "1080:8080"
environment:
- APP_KEY=viAJ8Y2JmMAiwKrPYLmNYhbiooAowypX
- DB_HOST=172.18.0.2
- DB_PORT=3306
- DB_CONNECTION=mysql
- DB_DATABASE=firefly
- DB_USERNAME=root
- DB_PASSWORD=123456
mysql:
image: mysql:8.0.31
container_name: mysql
restart: on-failure:3
networks:
qgxnetwork:
ipv4_address: 172.18.0.2
command:
- --default-authentication-plugin=mysql_native_password
- --character-set-server=utf8mb4
- --collation-server=utf8mb4_general_ci
- --explicit_defaults_for_timestamp=true
volumes:
- /home/qigx/halo/mysql:/var/lib/mysql
- /home/qigx/halo/mysqlBackup:/data/mysqlBackup
#创建firefly的database脚本在此目录下,映射到docker的docker-entrypoint-initdb.d
- /home/qigx/firefly/sql:/docker-entrypoint-initdb.d
ports:
- "3306:3306"
healthcheck:
test: ["CMD", "mysqladmin", "ping", "-h", "127.0.0.1", "--silent"]
interval: 3s
retries: 5
start_period: 30s
environment:
# 请修改此密码,并对应修改上方 Halo 服务的 SPRING_R2DBC_PASSWORD 变量值
- MYSQL_ROOT_PASSWORD=123456
- MYSQL_DATABASE=halo
networks:
qgxnetwork:
ipam:
config:
- subnet: 172.18.0.0/24
三、启动容器
docker-compose up -d
评论区