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

在一个服务器上使用docker-compose方式搭建第二个halo,使用容器名连接数据库失败,使用容器ip可以成功 #5019

Closed
lizhengxing1993 opened this issue Dec 8, 2023 · 8 comments
Labels
kind/support Categorizes issue or PR as a support question.

Comments

@lizhengxing1993
Copy link

lizhengxing1993 commented Dec 8, 2023

系统信息

http://47.254.43.129:8080/console

使用的哪种方式运行?

Docker Compose

在线站点地址

http://47.254.43.129:8080/

发生了什么?

连接数据库使用容器名的方式,会导致数据库连接失败,使用容器ip可以成功
异常信息:Caused by: java.net.UnknownHostException: Failed to resolve 'halodb_8080:3306' [A(1)] after 2 queries

相关日志输出

halo_8080  | Caused by: org.springframework.dao.DataAccessResourceFailureException: Failed to obtain R2DBC Connection
halo_8080  |    at org.springframework.r2dbc.connection.ConnectionFactoryUtils.lambda$getConnection$0(ConnectionFactoryUtils.java:100) ~[spring-r2dbc-6.1.1.jar:6.1.1]
halo_8080  |    at reactor.core.publisher.Mono.lambda$onErrorMap$28(Mono.java:3799) ~[reactor-core-3.6.0.jar:3.6.0]
halo_8080  |    at reactor.core.publisher.FluxOnErrorResume$ResumeSubscriber.onError(FluxOnErrorResume.java:94) ~[reactor-core-3.6.0.jar:3.6.0]
halo_8080  |    ... 72 common frames omitted
halo_8080  | Caused by: java.net.UnknownHostException: Failed to resolve 'halodb_8080:3306' [A(1)] after 2 queries 
halo_8080  |    at io.netty.resolver.dns.DnsResolveContext.finishResolve(DnsResolveContext.java:1097) ~[netty-resolver-dns-4.1.101.Final.jar:4.1.101.Final]
halo_8080  |    ... 36 common frames omitted
halo_8080  | 
halo_8080 exited with code 0

附加信息

docker-compose.yml

version: "3"

services:
  halo_8080:
    image: halohub/halo:2.11
    container_name: halo_8080
    restart: on-failure:3
    depends_on:
      halodb_8080:
        condition: service_healthy
    networks:
      halo_network2:
    volumes:
      - ./halo2:/root/.halo2
    ports:
      - "8080: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://halodb_8080:3306/halo
      - --spring.r2dbc.username=root
      # MySQL 的密码,请保证与下方 MYSQL_ROOT_PASSWORD 的变量值一致。
      - --spring.r2dbc.password=@@@@@
      - --spring.sql.init.platform=mysql
      # 外部访问地址,请根据实际需要修改
      - --halo.external-url=http://47.254.43.129:8080/

  halodb_8080:
    image: mysql:8.1.0
    container_name: halodb_8080
    restart: on-failure:3
    networks:
      halo_network2:
    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:
      - "3307: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=@@@@
      - MYSQL_DATABASE=halo

networks:
  halo_network2:
@AeroWang
Copy link
Contributor

AeroWang commented Dec 8, 2023

有没有可能数据库端口绑定出了问题🤣

@lizhengxing1993
Copy link
Author

docker 网络问题

1 similar comment
@lizhengxing1993
Copy link
Author

docker 网络问题

@AeroWang
Copy link
Contributor

AeroWang commented Dec 8, 2023

不过突然想起来这个和我之前那个 next.js docker 形式解析后端服务 example_docker:port 解析不出来 ip 的问题好像,那个是 js 没解析出来,也是要通过具体 ip 访问后端本地服务。不懂

@lizhengxing1993
Copy link
Author

检查了容器间的通信是正常的,网络是在同一个网段,可以排除是网络原因,但是halo无法使用容器名的方式通信,应该是halo的bug

@ruibaby
Copy link
Member

ruibaby commented Dec 9, 2023

使用你的配置文件测试了一下,确实无法正常启动,但我尝试去掉 url 的 3306 端口之后就可以了,可能和 halo-dev/docs#269 (comment) 是同样的问题,目前不太清楚为什么会有这样的差异,但这和 Halo 本身应该无关。

此外,你的密码似乎设置的也不对。

图片 图片

最终可运行的 docker-compose.yaml:

version: "3"

services:
  halo_8080:
    image: halohub/halo:2.11
    container_name: halo_8080
    restart: on-failure:3
    depends_on:
      halodb_8080:
        condition: service_healthy
    networks:
      halo_network2:
    volumes:
      - ./halo2:/root/.halo2
    ports:
      - "8080: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://halodb_8080/halo
      - --spring.r2dbc.username=root
      # MySQL 的密码,请保证与下方 MYSQL_ROOT_PASSWORD 的变量值一致。
      - --spring.r2dbc.password=@@@@@
      - --spring.sql.init.platform=mysql
      # 外部访问地址,请根据实际需要修改
      - --halo.external-url=http://47.254.43.129:8080/

  halodb_8080:
    image: mysql:8.1.0
    container_name: halodb_8080
    restart: on-failure:3
    networks:
      halo_network2:
    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:
      - "3307: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=@@@@@
      - MYSQL_DATABASE=halo

networks:
  halo_network2:

@ruibaby ruibaby added the triage/needs-information Indicates an issue needs more information in order to work on it. label Dec 9, 2023
@guqing
Copy link
Member

guqing commented Dec 9, 2023

使用你的配置文件测试了一下,确实无法正常启动,但我尝试去掉 url 的 3306 端口之后就可以了,可能和 halo-dev/docs#269 (comment) 是同样的问题,目前不太清楚为什么会有这样的差异,但这和 Halo 本身应该无关。

原因参考这个:

#3241 (comment)

/remove-triage needs-information
/kind support
/close

@f2c-ci-robot f2c-ci-robot bot added the kind/support Categorizes issue or PR as a support question. label Dec 9, 2023
@f2c-ci-robot f2c-ci-robot bot closed this as completed Dec 9, 2023
Copy link

f2c-ci-robot bot commented Dec 9, 2023

@guqing: Closing this issue.

In response to this:

使用你的配置文件测试了一下,确实无法正常启动,但我尝试去掉 url 的 3306 端口之后就可以了,可能和 halo-dev/docs#269 (comment) 是同样的问题,目前不太清楚为什么会有这样的差异,但这和 Halo 本身应该无关。

原因参考这个:

#3241 (comment)

/remove-triage needs-information
/kind support
/close

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@f2c-ci-robot f2c-ci-robot bot removed the triage/needs-information Indicates an issue needs more information in order to work on it. label Dec 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/support Categorizes issue or PR as a support question.
Projects
None yet
Development

No branches or pull requests

4 participants