部署docker环境

centos8.2安装docker-ce

docker部署MySQL

拉取镜像

docker pull mysql

创建相关路径

mkdir -p /home/docker/mysql/{conf,data}

运行临时MySQL

docker run -d -p 3306:3306 --name mysql -e MYSQL_ROOT_PASSWORD=default123 mysql

复制配置文件到宿主机

docker cp mysql:/etc/mysql/my.cnf /home/docker/mysql/conf

删除临时MySQL

docker rm -f mysql

运行MySQL

docker run --name mysql \
-p 3306:3306 \
-e MYSQL_ROOT_PASSWORD=default123 \
-v /home/docker/mysql/conf/my.cnf:/etc/mysql/my.cnf \
-v /home/docker/mysql/data:/var/lib/mysql \
--restart always \
-d mysql

创建halo数据库

create database halodb character set utf8mb4 collate utf8mb4_bin;

docker部署halo

拉取镜像

docker pull halohub/halo

创建相关目录

mkdir -p /home/docker/halo

下载halo配置文件模板

cd /home/docker/halo
wget https://dl.halo.run/config/application-template.yaml -O ./application.yaml

修改配置文件

vim application.yaml

注释h2数据库连接配置,放开mysql数据库连接配置,修改密码为运行MySQL容器是指定的密码,此处为:default123

server:
  port: 8090

  # Response data gzip.
  compression:
    enabled: false
spring:
  datasource:

    # H2 database configuration.
    #driver-class-name: org.h2.Driver
    #url: jdbc:h2:file:~/.halo/db/halo
    #username: admin
    #password: 123456

    # MySQL database configuration.
    driver-class-name: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://127.0.0.1:3306/halodb?characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true
    username: root
    password: default123

  # H2 database console configuration.
  h2:
    console:
      settings:
        web-allow-others: false
      path: /h2-console
      enabled: false

halo:

  # Your admin client path is https://your-domain/{admin-path}
  admin-path: admin

  # memory or level
  cache: memory

运行halo

docker run --name halo \
-p 8090:8090 \
-v /home/docker/halo:/root/.halo \
--net host \
--restart always \
-d halohub/halo

浏览器访问ip+端口号访问即可进入博客安装界面

nginx代理https访问

docker环境nginx配置https访问

Q.E.D.