Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update docker-compose.md #276

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,13 @@ import DockerArgs from "./slots/docker-args.md"

services:
halo:
image: halohub/halo:2.10
image: halohub/halo:2.10.2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

建议不加上 patch 版本。主要是为了每次发布 patch 版本的时候不用频繁修改文档。

container_name: halo
restart: on-failure:3
depends_on:
halodb:
condition: service_healthy
- halodb
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里建议添加上 condition: service_healthy。如果没有 condition 的话,Halo 可能在数据库还没有准备好就启动,会造成 Halo 容器多余一次或多次重启。

参考:

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

在 Docker Compose 文件的版本 3 中,condition 形式的 depends_on 是不支持的。所以应该使用数组形式来声明依赖关系,而不是使用映射(map)和条件。

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

所以我改写成如下版本:

services:
  halo:
    image: halohub/halo:latest
    container_name: halo
    restart: on-failure
    depends_on:
      - halodb
    # 其他配置...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我这边实际测试了一下,这样修改之后反而是有问题的:

图片 图片

这样会让 Halo 和 MySQL 同时启动,就会造成 MySQL 容器还没有 ready,Halo 也无法启动。

根据文档 docs.docker.com/compose/compose-file/05-services/#long-syntax-1,当前的配置方式才是正确的,我想知道你是遇到什么问题才进行这个修改的吗?

Copy link
Author

@clien9025 clien9025 Nov 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

version: "3"

services:
  halo:
    image: halohub/halo:2.10.2
    container_name: halo
    restart: on-failure:3
    depends_on:
      - halodb
    networks:
      - halo_network
    volumes:
      - ./halo2:/root/.halo2
    ports:
      - "8090:8090"
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:8090/actuator/health/readiness"]
      interval: 30s
      timeout: 5s
      retries: 5
    command:
      - --spring.r2dbc.url=r2dbc:pool:mysql://halodb:3306/halo
      - --spring.r2dbc.username=root
      - --spring.r2dbc.password=zdasdasdad
      - --spring.sql.init.platform=mysql
      - --halo.external-url=http://123.12.123.123:8090/

  halodb:
    image: mysql:8.1.0
    container_name: halodb
    restart: on-failure:3
    networks:
      - halo_network
    command: 
      - --default-authentication-plugin=caching_sha2_password
      - --character-set-server=utf8mb4
      - --collation-server=utf8mb4_general_ci
      - --explicit_defaults_for_timestamp=true
    volumes:
      - ./mysql:/var/lib/mysql
      - ./mysqlBackup:/data/mysqlBackup
    ports:
      - "3306:3306"
    healthcheck:
      test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "--silent"]
      interval: 3s
      retries: 5
    environment:
      - MYSQL_ROOT_PASSWORD=zdasdasdad
      - MYSQL_DATABASE=halo

networks:
  halo_network:

以上的yaml配置文件就是我本人的配置,我本人已经运行成功,博客也在使用中。还是我上述的观点(如下):

在 Docker Compose 文件的版本 3 中,condition 形式的 depends_on 是不支持的。所以应该使用数组形式来声明依赖关系,而不是使用映射(map)和条件。

PS:上述的数据库的密码和地址请自行配置(本人已修改)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

~# docker-compose version
docker-compose version 1.25.0, build unknown
docker-py version: 4.1.0
CPython version: 3.8.2
OpenSSL version: OpenSSL 1.1.1f  31 Mar 2020

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Docker Compose 版本过旧,不支持我们文档提供的 depends_on 写法,1.25.0 已经是 2019 年的版本了。

https://github.com/docker/compose/blob/4038169d96ca176542c5265e21f4b18ee64b1dd9/compose/config/config_schema_v3.0.json#L79

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Docker Compose 版本过旧,不支持我们文档提供的 depends_on 写法,1.25.0 已经是 2019 年的版本了。

https://github.com/docker/compose/blob/4038169d96ca176542c5265e21f4b18ee64b1dd9/compose/config/config_schema_v3.0.json#L79

好的,谢谢,了解了

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

那我就关闭这个 PR 了。

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

networks:
halo_network:
- halo_network
volumes:
- ./halo2:/root/.halo2
ports:
Expand All @@ -134,7 +133,6 @@ import DockerArgs from "./slots/docker-args.md"
interval: 30s
timeout: 5s
retries: 5
start_period: 30s
command:
- --spring.r2dbc.url=r2dbc:pool:mysql://halodb:3306/halo
- --spring.r2dbc.username=root
Expand All @@ -149,7 +147,7 @@ import DockerArgs from "./slots/docker-args.md"
container_name: halodb
restart: on-failure:3
networks:
halo_network:
- halo_network
command:
- --default-authentication-plugin=caching_sha2_password
- --character-set-server=utf8mb4
Expand All @@ -161,17 +159,17 @@ import DockerArgs from "./slots/docker-args.md"
ports:
- "3306:3306"
healthcheck:
test: ["CMD", "mysqladmin", "ping", "-h", "127.0.0.1", "--silent"]
test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "--silent"]
interval: 3s
retries: 5
start_period: 30s
environment:
# 请修改此密码,并对应修改上方 Halo 服务的 SPRING_R2DBC_PASSWORD 变量值
- MYSQL_ROOT_PASSWORD=o#DwN&JSa56
- MYSQL_DATABASE=halo

networks:
halo_network:

```

3. 仅创建 Halo 实例(使用默认的 H2 数据库,**不推荐用于生产环境,建议体验和测试的时候使用**):
Expand Down
Loading