palantir / gradle-docker

a Gradle plugin for orchestrating docker builds and pushes.
Apache License 2.0
745 stars 158 forks source link

Problem on mac: "Cannot run program "docker": error=2, No such file or directory" #162

Closed solomkinmv closed 6 years ago

solomkinmv commented 6 years ago

When I try to build docker I receive following error message: Starting process 'command 'docker''. Working directory: /Users/msolomkin/Projects/glossary/discovery-server/build/docker Command: docker build --build-arg JAR_FILE=discovery-server-0.0.1-SNAPSHOT.jar -t solomkinmv/discovery-server .

But when I go to the working directory (/Users/msolomkin/Projects/glossary/discovery-server/build/docker) manually and run command docker build --build-arg JAR_FILE=discovery-server-0.0.1-SNAPSHOT.jar -t solomkinmv/discovery-server . everything works fine.

Here is the stack trace:

FAILURE: Build failed with an exception.

  • What went wrong: Execution failed for task ':discovery-server:docker'.

    A problem occurred starting process 'command 'docker''

  • Try: Run with --debug option to get more log output. Run with --scan to get full insights.

  • Exception is: org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':discovery-server:docker'. at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:100) at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:70) at org.gradle.api.internal.tasks.execution.OutputDirectoryCreatingTaskExecuter.execute(OutputDirectoryCreatingTaskExecuter.java:51) at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:62) at org.gradle.api.internal.tasks.execution.ResolveTaskOutputCachingStateExecuter.execute(ResolveTaskOutputCachingStateExecuter.java:54) at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:60) at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:97) at org.gradle.api.internal.tasks.execution.CleanupStaleOutputsExecuter.execute(CleanupStaleOutputsExecuter.java:87) at org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter.execute(ResolveTaskArtifactStateTaskExecuter.java:52) at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:52) at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:54) at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43) at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:34) at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker$1.run(DefaultTaskGraphExecuter.java:248) at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336) at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328) at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:199) at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:110) at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:241) at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:230) at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.processTask(DefaultTaskPlanExecutor.java:123) at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.access$200(DefaultTaskPlanExecutor.java:79) at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:104) at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:98) at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.execute(DefaultTaskExecutionPlan.java:626) at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.executeWithTask(DefaultTaskExecutionPlan.java:581) at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.run(DefaultTaskPlanExecutor.java:98) at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63) at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:46) at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55) Caused by: org.gradle.process.internal.ExecException: A problem occurred starting process 'command 'docker'' at org.gradle.process.internal.DefaultExecHandle.execExceptionFor(DefaultExecHandle.java:222) at org.gradle.process.internal.DefaultExecHandle.setEndStateInfo(DefaultExecHandle.java:202) at org.gradle.process.internal.DefaultExecHandle.failed(DefaultExecHandle.java:342) at org.gradle.process.internal.ExecHandleRunner.run(ExecHandleRunner.java:86) at org.gradle.internal.operations.BuildOperationIdentifierPreservingRunnable.run(BuildOperationIdentifierPreservingRunnable.java:39) ... 3 more Caused by: net.rubygrapefruit.platform.NativeException: Could not start 'docker' at net.rubygrapefruit.platform.internal.DefaultProcessLauncher.start(DefaultProcessLauncher.java:27) at net.rubygrapefruit.platform.internal.WrapperProcessLauncher.start(WrapperProcessLauncher.java:36) at org.gradle.process.internal.ExecHandleRunner.run(ExecHandleRunner.java:68) ... 4 more Caused by: java.io.IOException: Cannot run program "docker" (in directory "/Users/msolomkin/Projects/glossary/discovery-server/build/docker"): error=2, No such file or directory at net.rubygrapefruit.platform.internal.DefaultProcessLauncher.start(DefaultProcessLauncher.java:25) ... 6 more Caused by: java.io.IOException: error=2, No such file or directory ... 7 more

Also, my Travis is able to build docker image. Looks like plugin can't run docker command if Docker is installed with Docker for Mac.

Docker for Mac version: 17.12.0-ce-mac49 (21995) Gradle version: 4.4.1 Plugin version: 0.17.2

Here is my task configuration:

docker {
    name "solomkinmv/${bootJar.baseName}"
    println "==> Docker task for ${name}"
    files bootJar.archivePath
    buildArgs(['JAR_FILE': "${bootJar.archiveName}"])
}

And here is the link to GitHub: https://github.com/solomkinmv/glossary/tree/discovery-server/discovery-server

uschi2000 commented 6 years ago

Hmm, I don't know what's going on here. I can confirm that we use Docker for Mac and equivalent Gradle setups very widely.

solomkinmv commented 6 years ago

@uschi2000 I've tried other Mac and it worked from the terminal but failed from IntelliJ IDEA. Looks like Transmode plugin has related issues: https://github.com/Transmode/gradle-docker/issues/65 and https://github.com/Transmode/gradle-docker/issues/80

But this doesn't explain why on my second mac I can't run gradle task from terminal

uschi2000 commented 6 years ago

OK. FYI, I have never run the dockerTag task from IntelliJ, but running it from the terminal works reliably over here.

One thing to try is to wipe any existing old Docker installations, in particular if you have upgraded from pre-Docker-for-Mac times.

solomkinmv commented 6 years ago

@uschi2000 Ok, and the most interesting. After a few hours of sleep, the mac is able to execute docker task

rikbrown commented 6 years ago

I'm also experiencing this and it seems to be because the PATH environment variable running under Gradle's Exec plugin (which this plugin uses to shell out to Docker) does not include /usr/local/bin. In my case, I installed Docker using Homebrew which placed it there.

And you cannot symlink into /usr/bin on Mac because of SIP :)

And... even using a hack to set the PATH in another task doesn't work because Gradle Exec seems to create it's own PATH. It looks like you can customise the environment variables in the Exec task, but my Gradle build file obviously doesn't have access to the plugin's task.

The Transmode version of this plugin provides an option to specify the Docker path.

I'm still experimenting how to get around this, but would the maintainers be interested in a PR either adding /usr/local/bin to the PATH, or allowing the Docker executable to be specified?

rikbrown commented 6 years ago

Actually,

16:29:22.403 [DEBUG] [org.gradle.process.internal.DefaultExecHandle] Environment for process 'command 'docker'': {PATH=/usr/local/bin:/usr/bin:/bin:/sbin, SSH_AUTH_SOCK=/private/tmp/com.apple.launchd.fJgV7kOz0e/Listeners, SHELL=/usr/local/bin/fish, XPC_FLAGS=0x0, __CF_USER_TEXT_ENCODING=0x1F5:0x0:0x2, Apple_PubSub_Socket_Render=/private/tmp/com.apple.launchd.SeKo73ESRr/Render, LOGNAME=rik, JAVA_MAIN_CLASS_60268=org.gradle.launcher.daemon.bootstrap.GradleDaemon, USER=rik, XPC_SERVICE_NAME=com.jetbrains.intellij.12692, HOME=/Users/rik, TMPDIR=/var/folders/l1/jjdsl7157k35tc1w0s2n0zg40000gn/T/}

PATH seems correct but Gradle Exec is ignoring it. I found a Stackoverflow suggesting this might be a Gradle bug: https://stackoverflow.com/questions/31403573/specify-path-environment-does-not-work-when-running-gradle-exec (and restarting Gradle per one of the answers did not help me).

Making a task to run just env also confirms that the PATH is correct. It's so curious why this is failing to run docker:

> Task :w=execEnv
PATH=/usr/local/bin:/usr/bin:/bin:/sbin
SHELL=/usr/local/bin/fish
JAVA_MAIN_CLASS_60268=org.gradle.launcher.daemon.bootstrap.GradleDaemon
USER=rik
TMPDIR=/var/folders/l1/jjdsl7157k35tc1w0s2n0zg40000gn/T/
SSH_AUTH_SOCK=/private/tmp/com.apple.launchd.fJgV7kOz0e/Listeners
XPC_FLAGS=0x0
__CF_USER_TEXT_ENCODING=0x1F5:0x0:0x2
Apple_PubSub_Socket_Render=/private/tmp/com.apple.launchd.SeKo73ESRr/Render
LOGNAME=rik
XPC_SERVICE_NAME=com.jetbrains.intellij.12692
HOME=/Users/rik
rikbrown commented 6 years ago

Dug into this some more.

Gradle is using ProcessBuilder to run commands here.

It looks like ProcessBuilder, at least on my system (macOS 10.13.3), itself does not respect the PATH variable. The following also failed:

task execSomething {
   new ProcessBuilder("docker").start()
}

This is dumb. There's a few Stackoverflow results suggesting the behaviour isn't well defined.

pkoenig10 commented 6 years ago

@rikbrown does this work for you when running the task from the command line? Other people seem to have only hit this issue when running in Intellij or Eclipse.

rikbrown commented 6 years ago

Yup - I had all these issues from the command line in macOS 13.13.3 with Docker installed via Homebrew at /usr/local/bin/docker. The PR I submitted fixes it though by being explicit on the path. I think it's some Java/OS combination weirdness.

pkoenig10 commented 6 years ago

What version of gradle are you using?

rikbrown commented 6 years ago

4.6 (reported by gradle --version)

pkoenig10 commented 6 years ago

I was able to recreate this with the following build.gradle using gradle 4.6 in an otherwise newly generated gradle project:

plugins {
    id 'com.palantir.docker' version '0.19.2'
}

docker {
    name 'test'
}

When I try to run the docker task it fails:

$ ./gradlew docker --stacktrace

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':docker'.
> A problem occurred starting process 'command 'docker''

* Try:
Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':docker'.
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:103)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:73)
        at org.gradle.api.internal.tasks.execution.OutputDirectoryCreatingTaskExecuter.execute(OutputDirectoryCreatingTaskExecuter.java:51)
        at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:59)
        at org.gradle.api.internal.tasks.execution.ResolveTaskOutputCachingStateExecuter.execute(ResolveTaskOutputCachingStateExecuter.java:54)
        at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:59)
        at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:101)
        at org.gradle.api.internal.tasks.execution.FinalizeInputFilePropertiesTaskExecuter.execute(FinalizeInputFilePropertiesTaskExecuter.java:44)
        at org.gradle.api.internal.tasks.execution.CleanupStaleOutputsExecuter.execute(CleanupStaleOutputsExecuter.java:88)
        at org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter.execute(ResolveTaskArtifactStateTaskExecuter.java:62)
        at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:52)
        at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:54)
        at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
        at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:34)
        at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker$1.run(DefaultTaskGraphExecuter.java:248)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:199)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:110)
        at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:241)
        at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:230)
        at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.processTask(DefaultTaskPlanExecutor.java:123)
        at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.access$200(DefaultTaskPlanExecutor.java:79)
        at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:104)
        at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:98)
        at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.execute(DefaultTaskExecutionPlan.java:623)
        at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.executeWithTask(DefaultTaskExecutionPlan.java:578)
        at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.run(DefaultTaskPlanExecutor.java:98)
        at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
        at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:46)
        at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
Caused by: org.gradle.process.internal.ExecException: A problem occurred starting process 'command 'docker''
        at org.gradle.process.internal.DefaultExecHandle.execExceptionFor(DefaultExecHandle.java:226)
        at org.gradle.process.internal.DefaultExecHandle.setEndStateInfo(DefaultExecHandle.java:204)
        at org.gradle.process.internal.DefaultExecHandle.failed(DefaultExecHandle.java:349)
        at org.gradle.process.internal.ExecHandleRunner.run(ExecHandleRunner.java:85)
        at org.gradle.internal.operations.BuildOperationIdentifierPreservingRunnable.run(BuildOperationIdentifierPreservingRunnable.java:39)
        ... 3 more
Caused by: net.rubygrapefruit.platform.NativeException: Could not start 'docker'
        at net.rubygrapefruit.platform.internal.DefaultProcessLauncher.start(DefaultProcessLauncher.java:27)
        at net.rubygrapefruit.platform.internal.WrapperProcessLauncher.start(WrapperProcessLauncher.java:36)
        at org.gradle.process.internal.ExecHandleRunner.run(ExecHandleRunner.java:67)
        ... 4 more
Caused by: java.io.IOException: Cannot run program "docker" (in directory "/Volumes/git/gradle-docker-test/build/docker"): error=2, No such file or directory
        at net.rubygrapefruit.platform.internal.DefaultProcessLauncher.start(DefaultProcessLauncher.java:25)
        ... 6 more
Caused by: java.io.IOException: error=2, No such file or directory
        ... 7 more

* Get more help at https://help.gradle.org

BUILD FAILED in 0s
2 actionable tasks: 1 executed, 1 up-to-date

I tried creating a simple test task similar to the dockerRun task to debug:

task dockerVersion(type: Exec) {
    workingDir "${project.buildDir}/docker" // same workingDir as dockerRun task
    commandLine 'docker', 'version'
}

This task failed with the same error as above. However I noticed that if I created the build/docker directory before running the task would succeed. So, at least in my case, the "No such file or directory" was referring to the working directory, not the specified executable.

My stacktrace matches the one originally reported, so I suspect that may be the root cause of this issue.

@rikbrown does the stacktrace on your failing command look similar to mine and the one originally posted here? If so, does creating the working directory first allow the task to complete successfully?

oopsoh commented 6 years ago

@uschi2000 this issus on mac always exist. After a few hours of sleep, it can be work , but after one day or later, it work failed. @pkoenig10 does creating the working directory first can not allow the task to complete successfully.

gradle version 4.6 gradle docker plugin 0.19.2

aandriyc commented 6 years ago

If you still facing this, it seems to be caused by gradle daemon that somehow caches environment state. Killing gradle daemon solves it. Or just disable daemon by adding org.gradle.daemon=false to ~/.gradle/gradle.properties

oopsoh commented 6 years ago

In this case, the gradle daemon is stopped manually each time and then re-executed. If you turn it off in configuration, the compilation speed will slow down, which is certainly a solution, but not the perfect one

aandriyc commented 6 years ago

Sure. It’s rather work around than a solution

pkoenig10 commented 6 years ago

@oopsoh If you're still seeing failures can share your build.gradle file and the output of ./gradlew docker --stacktrace?

arutsudar commented 6 years ago

In IntelliJ,

Try this :

View -> Tool Windows -> Gradle -> ProjectName(build.gradle) -> Tasks -> i) build -> build ii) docker -> docker

and try your command again

mlindleyjr commented 6 years ago

If anyone is still facing this, the simplest solution I found was to launch intellij from the terminal using open -a 'Intellij IDEA CE' or open -a 'Intellij IDEA' depending on your installed edition.

I haven't spent much time on specifics, but further discussion on probable root cause can be found here.

zhuangjinjin commented 5 years ago

I had same error from command line in macOS(10.13.6), with the following build.gradle in Gradle 4.10.3

plugins {
    id "com.palantir.docker" version "0.22.1"
}
docker {
    name "spring-boot-with-docker"
}

When I try run docker task, it fails

$ gradle docker --stacktrace
> Task :docker FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':docker'.
> A problem occurred starting process 'command 'docker''

* Try:
Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':docker'.
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:110)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:77)
        at org.gradle.api.internal.tasks.execution.OutputDirectoryCreatingTaskExecuter.execute(OutputDirectoryCreatingTaskExecuter.java:51)
        at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:59)
        at org.gradle.api.internal.tasks.execution.ResolveTaskOutputCachingStateExecuter.execute(ResolveTaskOutputCachingStateExecuter.java:54)
        at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:59)
        at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:101)
        at org.gradle.api.internal.tasks.execution.FinalizeInputFilePropertiesTaskExecuter.execute(FinalizeInputFilePropertiesTaskExecuter.java:44)
        at org.gradle.api.internal.tasks.execution.CleanupStaleOutputsExecuter.execute(CleanupStaleOutputsExecuter.java:91)
        at org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter.execute(ResolveTaskArtifactStateTaskExecuter.java:62)
        at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:59)
        at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:54)
        at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
        at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:34)
        at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.run(EventFiringTaskExecuter.java:51)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:301)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:293)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:175)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:91)
        at org.gradle.internal.operations.DelegatingBuildOperationExecutor.run(DelegatingBuildOperationExecutor.java:31)
        at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter.execute(EventFiringTaskExecuter.java:46)
        at org.gradle.execution.taskgraph.LocalTaskInfoExecutor.execute(LocalTaskInfoExecutor.java:42)
        at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$BuildOperationAwareWorkItemExecutor.execute(DefaultTaskExecutionGraph.java:277)
        at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$BuildOperationAwareWorkItemExecutor.execute(DefaultTaskExecutionGraph.java:262)
        at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$ExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:135)
        at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$ExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:130)
        at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$ExecutorWorker.execute(DefaultTaskPlanExecutor.java:200)
        at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$ExecutorWorker.executeWithWork(DefaultTaskPlanExecutor.java:191)
        at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$ExecutorWorker.run(DefaultTaskPlanExecutor.java:130)
        at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
        at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:46)
        at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
Caused by: org.gradle.process.internal.ExecException: A problem occurred starting process 'command 'docker''
        at org.gradle.process.internal.DefaultExecHandle.execExceptionFor(DefaultExecHandle.java:231)
        at org.gradle.process.internal.DefaultExecHandle.setEndStateInfo(DefaultExecHandle.java:209)
        at org.gradle.process.internal.DefaultExecHandle.failed(DefaultExecHandle.java:355)
        at org.gradle.process.internal.ExecHandleRunner.run(ExecHandleRunner.java:85)
        at org.gradle.internal.operations.CurrentBuildOperationPreservingRunnable.run(CurrentBuildOperationPreservingRunnable.java:42)
        ... 3 more
Caused by: net.rubygrapefruit.platform.NativeException: Could not start 'docker'
        at net.rubygrapefruit.platform.internal.DefaultProcessLauncher.start(DefaultProcessLauncher.java:27)
        at net.rubygrapefruit.platform.internal.WrapperProcessLauncher.start(WrapperProcessLauncher.java:36)
        at org.gradle.process.internal.ExecHandleRunner.run(ExecHandleRunner.java:67)
        ... 4 more
Caused by: java.io.IOException: Cannot run program "docker" (in directory "/Users/jin/Documents/workspace/java/spring-boot-with-docker/build/docker"): error=2, No such file or directory
        at net.rubygrapefruit.platform.internal.DefaultProcessLauncher.start(DefaultProcessLauncher.java:25)
        ... 6 more
Caused by: java.io.IOException: error=2, No such file or directory
        ... 7 more

* Get more help at https://help.gradle.org

BUILD FAILED in 1s
2 actionable tasks: 1 executed, 1 up-to-date

It seem that could't found the path of docker

$ which docker
/usr/local/bin/docker
brightshine1111 commented 5 years ago

Any update on this? I'm running into this issue trying to run my gradle docker task from within a gradle builder docker image (docker-ception a bit). I've seen the same error as others both on a mac (where docker is installed at /usr/local/bin/docker) and on Linux build machines (/usr/bin/docker).

missingfaktor commented 5 years ago

Thanks, @aandriyc! You are a life saver.

Que3216 commented 4 years ago

Confirmed that launching IntelliJ from the terminal fixes this problem as per this answer https://github.com/palantir/gradle-docker/issues/162#issuecomment-424765627.

@uschi2000 If the actual problem is hard to fix, would it make sense to check docker existence, and log an error message with common tips on fixing the problem if docker cannot be found (e.g. run IntelliJ from the console)? Worried about devs wasting time on this if it's a common issue. Imagine also just checking /usr/local/bin/docker would fix the issue on most macs.

robbie70 commented 3 years ago

UPDATE : I was following a tutorial when I got the below message. It turns out that you need have Docker installed for the tutorial to work. So I have installed Docker For Mac and it works fine now. My below is probably a red-herring now.


neither of the suggested fixes https://github.com/palantir/gradle-docker/issues/162#issuecomment-424765627 or https://github.com/palantir/gradle-docker/issues/162#issuecomment-397486394 work for me. I am also working with Intellij on a Mac.

Get the same message that has been reported above (see output below). When run using Gradle Scan I get a clearer message though,

A problem occurred starting process 'command 'docker''

Could not start 'docker' Cannot run program "docker" (in directory "/Users/xyz/dev/src/github/xyz/poc/docker-jenkins/build/docker"): error=2, No such file or directory error=2, No such file or directory

Its this

"no such file or directory"

which I dont understand. This mentioned directory does exist and contains two files, 'Dockerfile' and 'plugins.txt'

Terminal Output

`$ ./gradlew --stop Stopping Daemon(s) 1 Daemon stopped rob-MacBook:docker-jenkins$ ./gradlew --stop No Gradle daemons are running. rob-MacBook:docker-jenkins:docker-jenkins$ ./gradlew docker Starting a Gradle Daemon, 3 stopped Daemons could not be reused, use --status for details

Task :docker FAILED

FAILURE: Build failed with an exception.

  • What went wrong: Execution failed for task ':docker'.

    A problem occurred starting process 'command 'docker''

  • Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

  • Get more help at https://help.gradle.org

BUILD FAILED in 3s 3 actionable tasks: 3 executed `

build.gradle `plugins { id 'base' id 'com.palantir.docker' version '0.25.0' id 'com.palantir.docker-run' version '0.25.0' id 'pl.allegro.tech.build.axion-release' version '1.12.0' }

project.version = scmVersion.version

docker { name "${project.name}:${project.version}" files "plugins.txt" }

dockerRun { name "${project.name}" image "${project.name}:${project.version}" ports '8080:8080' clean true daemonize false }`

thiagocavalcanti commented 8 months ago

After many investigation, a simple restart on my Mac did the trick :) In my case, i'd just update my JAVA_HOME to a new version and started to get this errors (i'm using docker-compose instead too)

PavloSmokorovskiy commented 4 months ago

The problem is IntelliJ IDEA uses different shells Open Preferences in IntelliJ IDEA go to Tools > Terminal Change /bin/zsh to /bin/bash

KKghub commented 1 month ago

If you still facing this, it seems to be caused by gradle daemon that somehow caches environment state. Killing gradle daemon solves it. Or just disable daemon by adding org.gradle.daemon=false to ~/.gradle/gradle.properties

The above solved the issue for my MacBook. Although I did not add the above line to my gradle.properties, instead just restarted my gradle daemon using IntelliJ.

To do that you can simply Hit Shift twice and search "Show gradle daemons" and click on stop all button to kill all the daemons. https://stackoverflow.com/questions/69468990/momentarily-kill-or-restart-gradle-daemon-from-inside-intellij-idea-gradle-s

pravatk commented 1 week ago

I am running gradle 8.10.2 and I encountered the above issue.

Below command worked for me to stop the daemon and restart the jib command to have everything working. ./gradlew --stop