【问题标题】:Unable to connect to myslq docker container on jenkins pipeline无法连接到 jenkins 管道上的 mysql docker 容器
【发布时间】:2020-03-26 00:01:41
【问题描述】:

我正在尝试连接到我使用 docker compose 创建的 mysql docker 容器。

version: '3.1'
services:
  mysql:
    image: mysql:5.7.12
    ports:
      - "6033:3306"
    command: --sql_mode="" --default-authentication-plugin=mysql_native_password --transaction-isolation=READ-UNCOMMITTED
    restart: always
    container_name: docker-mysql
    environment:
      MYSQL_DATABASE: transaction_summary
      MYSQL_ROOT_PASSWORD: root

然后在管道脚本中运行 .gradlew test 命令来运行测试。但是,它失败并抱怨无法连接到数据库。 使用的 Jenkins 标签是 Ubuntu-18。 我的网址在应用程序中如下所示。

url: jdbc:mysql://localhost:6033/transaction_summary

当我在笔记本电脑上运行它时,它运行良好。但它在詹金斯上失败了。 我在 jenkins 脚本中添加了 docker ps 以确保容器正在运行。它正在运行,并提供以下详细信息:

197fbf0c793a   mysql:5.7.12  "docker-entrypoint.s…"  0.0.0.0:6033->3306/tcp  docker-mysql

我尝试使用 127.0.0.1、0.0.0.0、127.0.0.2 而不是 localhost。它仍然在抱怨。

【问题讨论】:

    标签: mysql docker jenkins docker-compose jenkins-pipeline


    【解决方案1】:

    可以尝试图像名称,即mysql 网址可能看起来像jdbc:mysql://mysql:6033/transaction_summary

    【讨论】:

      猜你喜欢
      • 2023-02-23
      • 2020-07-22
      • 2016-04-26
      • 2016-07-22
      • 2020-02-08
      • 2020-12-30
      • 2020-07-29
      • 2022-11-18
      • 2020-10-20
      相关资源
      最近更新 更多