Docker - executable file not found in $PATH

元气小坏坏 提交于 2021-02-05 07:56:07

问题


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?


回答1:


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




回答2:


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 docker-swarm or kubernetes it's important that the image be self-contained and has the script included in it.




回答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



来源:https://stackoverflow.com/questions/51766629/docker-executable-file-not-found-in-path

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!