Docker compose gradle 插件以“dockerspect”退出需要至少 1 个参数

发布于 2025-01-10 11:30:24 字数 1775 浏览 0 评论 0原文

我有以下 docker-compose 文件:

version: '3.1'

services:

  localstack:
    image: localstack/localstack:0.9.6
    ports:
      - "4576:4576"
    environment:
      - SERVICES=sqs:4576
      - HOSTNAME_EXTERNAL=localhost
      - DEBUG=0
      - START_WEB=0

  primarydb:
    image: mysql:5.6
    environment:
      MYSQL_USER: test-user
      MYSQL_PASSWORD: test-password
      MYSQL_DATABASE: testdb
      MYSQL_ROOT_PASSWORD: test-password
    ports:
      - "3318:3306"

我有以下 gradle 配置:

    apply plugin: 'docker-compose'
    dockerCompose.isRequiredBy(project.tasks.getByName('test'))

    dockerCompose {
        useComposeFiles = ['docker-compose.yml']
        startedServices = ['localstack', 'primarydb']

        projectName = "${rootProject.name}"
    }

    project.tasks.getByName('test').doFirst {
        systemProperty 'localstack.sqs.endpoint', "http://localhost:4576"
        systemProperty 'mysql.url', "jdbc:mysql://localhost:3318"
    }

我正在使用最新的 docker-compose 插件: com.avast.gradle:gradle-docker-compose-plugin:0.15.1

由于某种原因,该构建可以在我朋友的 Linux 机器上运行,但不能在 MacOS 11.4 上运行。 当我运行 ./gradlew composeUp 任务时,它失败并显示以下错误消息:

./gradlew composeUp      

> Configure project :
2.5.25-SNAPSHOT

> Task :composeUp
Container primarydb-1  Running
Container localstack-1  Recreate
Container localstack-1  Recreated
Container localstack-1  Starting
Container localstack-1  Started
"docker inspect" requires at least 1 argument.
See 'docker inspect --help'.

Usage:  docker inspect [OPTIONS] NAME|ID [NAME|ID...]

Return low-level information on Docker objects

> Task :composeUp FAILED
...

知道为什么这个插件不能在 Mac 上运行,但可以在我朋友的机器上运行吗?

I have the following docker-compose file:

version: '3.1'

services:

  localstack:
    image: localstack/localstack:0.9.6
    ports:
      - "4576:4576"
    environment:
      - SERVICES=sqs:4576
      - HOSTNAME_EXTERNAL=localhost
      - DEBUG=0
      - START_WEB=0

  primarydb:
    image: mysql:5.6
    environment:
      MYSQL_USER: test-user
      MYSQL_PASSWORD: test-password
      MYSQL_DATABASE: testdb
      MYSQL_ROOT_PASSWORD: test-password
    ports:
      - "3318:3306"

And I have the following gradle configuration:

    apply plugin: 'docker-compose'
    dockerCompose.isRequiredBy(project.tasks.getByName('test'))

    dockerCompose {
        useComposeFiles = ['docker-compose.yml']
        startedServices = ['localstack', 'primarydb']

        projectName = "${rootProject.name}"
    }

    project.tasks.getByName('test').doFirst {
        systemProperty 'localstack.sqs.endpoint', "http://localhost:4576"
        systemProperty 'mysql.url', "jdbc:mysql://localhost:3318"
    }

And I am using the latest docker-compose plugin: com.avast.gradle:gradle-docker-compose-plugin:0.15.1

For some reason, the build works on my friend's Linux machine, but it doesn't work on MacOS 11.4.
When I run ./gradlew composeUp task it just fails with the following error message:

./gradlew composeUp      

> Configure project :
2.5.25-SNAPSHOT

> Task :composeUp
Container primarydb-1  Running
Container localstack-1  Recreate
Container localstack-1  Recreated
Container localstack-1  Starting
Container localstack-1  Started
"docker inspect" requires at least 1 argument.
See 'docker inspect --help'.

Usage:  docker inspect [OPTIONS] NAME|ID [NAME|ID...]

Return low-level information on Docker objects

> Task :composeUp FAILED
...

Any idea why this plugin doesn't work on a mac but works on my friend's machine?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

狼性发作 2025-01-17 11:30:24

我遇到了同样的错误。运行 ./gradle composeUp --stacktrace 给出了 com.avast.gradle:gradle-docker-compose-plugin:0.15.1 正在做什么的线索。本质上是:

  1. docker-compose -pup
  2. docker-compose -p <项目名称>; config --services 和最后
  3. docker-compose -p <项目名称>; ps --services

最后一步是我失败的一步(也是目前你失败的一步。)手动重复 compose-commands 并查看 Docker 桌面 UI,我可以看到,那个 docker-compose 确实通过删除其中的任何点来改变我的项目名称。重新指定后

dockerCompose {
    [...]
    projectName = 'name-without-dots'
}

,确保 docker-compose 不会更改项目名称,确实为我解决了问题。

您的错误原因可能仍然是不同的。尝试使用 --stacktrace--info 甚至 --debug 运行 ./gradlew composeUp 来获取更好地了解出了什么问题。

I faced the same error. Running ./gradle composeUp --stacktrace gave a clue what com.avast.gradle:gradle-docker-compose-plugin:0.15.1 is doing. In essence to does:

  1. docker-compose -p <project name> up
  2. docker-compose -p <project name> config --services and finally
  3. docker-compose -p <project name> ps --services

The third a last step is the one which was failing on me (and is the one currently failing on you.) Repeating the compose-commands manually and having a look into the Docker Desktop UI I could see, that docker-compose did alter my project-name by removing any dots from it. After respecifying

dockerCompose {
    [...]
    projectName = 'name-without-dots'
}

thus ensuring that docker-compose wont alter the project name, did solve the issue for me.

Your error cause migth still be a different one. Try running ./gradlew composeUp with --stacktrace, --info or even --debug to get a better understanding of what is going wrong.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文