You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Docker Compose执行./gradlew提示文件不存在但ls可见的问题

问题:Docker容器中gradlew文件存在但执行提示找不到

问题现象

  1. 初始使用以下docker-compose配置:
services:
  jar-build:
    image: myImage
    working_dir: /opt/build
    volumes:
      - "../:/opt/build/"
    command: "./gradlew build"

执行命令:

docker-compose -f aboveFile.yaml run jar-build

返回错误:

exec ./gradlew: no such file or directory

  1. 将command改为ls验证文件存在:
services:
  jar-build:
    image: myImage
    working_dir: /opt/build
    volumes:
      - "../:/opt/build/"
    command: "ls"

执行后输出明确包含gradlew文件:

Dockerfile
build.gradle
docker
gradle
gradle.properties
gradlew
gradlew.bat
jfrog.gradle
lombok.config
settings.gradle
src

环境与补充细节

  • 运行环境:Docker for Windows搭配Git Bash,使用Linux容器
  • 容器内当前用户:root(通过whoami命令确认)
  • gradlew文件首行Shebang:#!/bin/sh
  • Git Bash中echo $SHELL返回:C:Program FilesGitusrbinbash.exe
  • gradlew和docker-compose配置文件均使用LF换行符

后续操作与新问题

重新克隆仓库并设置git config --global core.autocrlf input后,原"找不到gradlew"的问题消失,但出现新错误:

Could not connect to the Gradle daemon.

内容的提问来源于stack exchange,提问作者moondc

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.03 21:50:35