Docker - executable file not found in $PATH

10,415

Solution 1

Docker works with long-lived immutable images and short-lived containers. If you have a script or any other sort of program you want to run, the best practice is generally to package it into an image and then run a container off of it. There is already a standard groovy image so your Dockerfile can be something as basic as:

FROM groovy:2.6
RUN mkdir /home/groovy/scripts
WORKDIR /home/groovy/scripts
COPY docker.groovy .
CMD ["groovy", "docker.groovy"]

You can develop and test your application locally, then use Docker to deploy it. Especially if you're looking at multi-host deployment solutions like or it's important that the image be self-contained and has the script included in it.

Solution 2

Your server and your container have different filesystems, unless you specify otherwise mounting a server folder on a container folder with --volume command.

Here you expect your container to know about docker.groovy file juste because you run the command in the server folder containing the file.

One way to do this would be to start a container with your current server folder mounted in a random in your container, and run the groovy script as an entrypoint. Something like this (untested)

docker run -v .:/random groovy_repo_1 /random/docker.groovy

Solution 3

  • Does the file exist... in the path and inside the container?

The path inside the container may be different from the path on your host. You can update the PATH environment variable during the build, or you can call the binary with a full path, e.g. /home/container_user/scripts/docker.groovy (we don't know where this file is inside your container from the question provided). That path needs to be to the script inside of your container, docker doesn't have direct access to the host filesystem, but you can run your container with a volume mount to bind mount a path on the host into the container.

  • If it is a shell script, check the first line, e.g. #!/bin/bash

You may have a groovy command at the top of your script. This binary must exist inside the container, and be in your path that's defined inside the container.

  • Check for windows linefeeds on linux shell scripts

If the script was written on windows, you may have the wrong linefeeds in the script. It will look for groovy\r instead of groovy and the first command won't exist.

  • If it is a binary, there is likely a missing library

You'll see this if the groovy binary was added with something like a COPY command, instead of compiling locally or installing from the package manager. You can use ldd /path/to/groovy inside the container to inspect the linked libraries.

This list is from my DC2018 presentation: https://sudo-bmitch.github.io/presentations/dc2018/faq-stackoverflow.html#59

Share:
10,415
Wicia
Author by

Wicia

Updated on June 04, 2022

Comments

  • Wicia
    Wicia almost 2 years

    In my Ubuntu Server I have following directory structure: /home/docker/groovy. In this location I have simple groovy file. On Docker it is running container groovy_repo_1.

    After I entered groovy directory I wanted to perform such script on container:

    docker exec groovy_repo_1 docker.groovy
    

    Output:

    rpc error: code = 2 desc = oci runtime error: exec failed: 
    container_linux.go:247: starting container process caused "exec: 
    \"docker.groovy\": executable file not found in $PATH"
    

    Why is it happen?

  • Wicia
    Wicia over 5 years
    In the same way I will be able to run scripts on running Nexus container? Your command will not create and run Groovy container?
  • Rémy
    Rémy over 5 years
    I'm not sure I understood what you intend to do @Wicia ? If you're asking if your docker.groovy will be able to access a running Nexus, yes. You should read the how to use in hub.docker.com/_/groovy
  • Wicia
    Wicia over 5 years
    I want to run Nexus container and create extra repositories using groovy script.
  • Rémy
    Rémy over 5 years
    OK, so it's about startup configuration / initialisation. The pattern I'ld use here is writing a docker compose file, which would start you application (nexus / wildfly / database / whatever) plus a container which would wait for the apps to be running then run (groovy) scripts. It's explained here docs.docker.com/compose/startup-order. You'ld replace the db container by nexus / widfly, and the web container by the official groovy container executing your groovy init scripts.
  • Wicia
    Wicia over 5 years
    Thank you :) So in Docker, it is possible for containers to interact with each other, like running container A executes scripts on the running container B?
  • Rémy
    Rémy over 5 years
    Yes, here's an example about backing up a database from container A via container B : docs.docker.com/compose/compose-file/…. This concept is called a sidecar, as in microservicepatterns.org/design_patterns/container_sidecar