【问题标题】:Can't run gradle wrapper with docker build无法使用 docker build 运行 gradle wrapper
【发布时间】:2022-01-25 06:57:00
【问题描述】:

我有这个小版本:

FROM eclipse-temurin:17-jdk as build-java
COPY java-project /root/project
WORKDIR /root/project
RUN chmod +x ./gradlew
RUN ls
RUN ./gradlew ...
#9 [build-build-java 5/6] RUN ls
#9 sha256:2d05b1e31ea4eaa8a9343b4f48fadcf7351b9d55dcc9c27e572d7bb32c4d723c
#9 0.194 build
#9 0.194 build.gradle
#9 0.194 docker-compose.yml
#9 0.194 gradle
#9 0.194 gradlew
#9 0.194 gradlew.bat
#9 0.194 HELP.md
#9 0.194 lombok.config
#9 0.194 settings.gradle
#9 0.194 src
#9 DONE 0.2s

#10 [build-build-java 6/6] RUN ./gradlew ...
#10 sha256:62cb4a1a6288008f3faccc3504e63ef87d30c3d7fde904a0576ffcf571e9b310
#10 0.310 /bin/sh: 1: ./gradlew: not found
#10 ERROR: executor failed running [/bin/sh -c ./gradlew ...]: exit code: 127

我已经被困了一段时间了。

我尝试使用FROM gradle,然后使用gradle ...,但随后出现此文件安装错误:

#10 sha256:26de7798a76971c3eb12e6398f830ee487fe41c110d0f8ca6a23a92ee5437267
#10 0.854 
#10 0.854 Welcome to Gradle 7.3.3!
#10 0.854
#10 0.854 Here are the highlights of this release:
#10 0.854  - Easily declare new test suites in Java projects
#10 0.855  - Support for Java 17
#10 0.855  - Support for Scala 3
#10 0.855
#10 0.855 For more details see https://docs.gradle.org/7.3.3/release-notes.html
#10 0.855
#10 0.952 Starting a Gradle Daemon (subsequent builds will be faster)
#10 2.153 Unable to list file systems to check whether they can be watched. Assuming all file systems can be watched. Re
ason: Could not query file systems: could not open mount file (errno 2: No such file or directory)

【问题讨论】:

  • 您是偶然从 Windows 构建映像的吗?
  • @thokuest 我是。我想知道这是否是 WSL 的一些错误?
  • Gradle 包装器 gradlew 是一个 shell 脚本,如果 shell 脚本以 DOS 行结尾被复制,您可能会收到类似这样的“未找到”错误。
  • 你的问题解决了吗?
  • 我看到有人发表了这个评论,我在 intellij 中将行尾从“CLRF”切换为“LF”,但它没有修复它@DavidMaze

标签: java docker gradle


【解决方案1】:

/bin/sh: 1: ./gradlew: not found 通常是由 bash 脚本中的回车 (\r) 行结尾引起的。删除回车最有可能解决问题。

【讨论】:

  • 我看到有人发表了这个评论,我在 intellij 中将行尾从“CLRF”切换为“LF”,但没有解决
【解决方案2】:

在 Windows 环境中遇到完全相同的问题。这与 shell 脚本文件的行尾有关。

我是这样解决的:

  1. 步骤 - 设置行尾以匹配 *nix 样式
git config --global core.autocrlf input
  1. 删除 git repo 并使用更新的配置重新克隆它

  2. 重新启动 docker 构建

注意!仅设置配置而不重新克隆存储库没有帮助。

【讨论】:

    【解决方案3】:

    我在 Windows 环境中遇到了同样的问题。正如@thokuest 所指出的,这是根据 bash 脚本中的回车 (\r) 行结尾发生的。但是您应该考虑,当您在 IntelliJ 中将行结尾从 CLRF 更改为 LF 时,容器中的 gradlew 文件不会相应更改,而是从您之前的 docker build . 命令缓存。所以你应该运行这个命令:

    docker build --no-cache .

    或:

    docker build --no-cache --progress=plain . 如果您想查看完整输出。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-11
      • 2017-11-21
      • 2022-10-07
      • 1970-01-01
      • 1970-01-01
      • 2013-09-20
      相关资源
      最近更新 更多