0

I have a gradle task which runs a bash script which in turn cleans up some docker containers, it's part of a pipeline of tasks.

If I run this task from the command line, it works fine; if I run it from within IntelliJ IDEA, it fails because I cannot find the docker command.

This is the task:

task localDockerClean(type: Exec) {
    executable './cleanDocker.sh'
    ignoreExitValue true
}

This is the script:

#! /bin/bash

echo "Init - Clean Docker Containers"
docker stop $(docker ps -a -q)
docker rm $(docker ps -a -q)
docker system prune --force --volumes
echo "End - Clean Docker Containers"

And this is the output that only happens when run from IntelliJ IDEA:

> Task :scripts:migrations:localDockerClean
Init - Clean Docker Containers
./cleanDocker.sh: line 4: docker: command not found
./cleanDocker.sh: line 4: docker: command not found
./cleanDocker.sh: line 5: docker: command not found
./cleanDocker.sh: line 5: docker: command not found
./cleanDocker.sh: line 6: docker: command not found
End - Clean Docker Containers

Looks like the script has no access to the docker command which is in the PATH in my MacOS but only when run from the IDE, otherwise it works fine.

Any idea how to fix this issue in my IDE?

Thank you!

SoManyGoblins
  • 5,605
  • 8
  • 45
  • 65
  • Did you install IntelliJ IDEA using some package manager, like flatpack or snap? Does it help if you install the IDE normally via tar.gz: https://www.jetbrains.com/idea/download/index.html? – CrazyCoder Apr 04 '22 at 19:29
  • I think I just downloaded the pkg file from the site and that's it. – SoManyGoblins Apr 04 '22 at 19:42
  • Sorry, didn't notice you are on macOS. How do you set PATH on your OS? See https://stackoverflow.com/a/26586170/104891. – CrazyCoder Apr 04 '22 at 19:42
  • Docker is already in my PATH, I don't need to set it again, the problem is in the IDE. – SoManyGoblins Apr 04 '22 at 19:57
  • 1
    IDE inherits the PATH environment from the process that started the IDE. On macOS environment can be different between the UI apps and the terminal shell depending on how you set it. To verify if it's the case, start the IDE from the terminal where Docker works for you using the command line: https://intellij-support.jetbrains.com/hc/en-us/articles/360011901879-How-to-start-IDE-from-the-command-line. Does the IDE see docker now? If yes, set your environment so that it's the same for the console and GUI apps per https://stackoverflow.com/a/26586170/104891. – CrazyCoder Apr 04 '22 at 19:59

0 Answers0