我有一个安装grunt的docker映像,但当我尝试运行它时,我得到一个错误:

Error response from daemon: Cannot start container foo_1: \
    exec: "grunt serve": executable file not found in $PATH

如果我在交互模式下运行bash, grunt是可用的。

我做错了什么?

这是我的Dockerfile:

# https://registry.hub.docker.com/u/dockerfile/nodejs/ (builds on ubuntu:14.04)
FROM dockerfile/nodejs

MAINTAINER My Name, me@email.com

ENV HOME /home/web
WORKDIR /home/web/site

RUN useradd web -d /home/web -s /bin/bash -m

RUN npm install -g grunt-cli
RUN npm install -g bower

RUN chown -R web:web /home/web
USER web

RUN git clone https://github.com/repo/site /home/web/site

RUN npm install
RUN bower install --config.interactive=false --allow-root

ENV NODE_ENV development

# Port 9000 for server
# Port 35729 for livereload
EXPOSE 9000 35729
CMD ["grunt"]

当你使用exec格式的命令(例如,CMD ["grunt"],一个带有双引号的JSON数组),它将在没有shell的情况下执行。这意味着大多数环境变量将不会出现。

如果你将命令指定为常规字符串(例如CMD grunt),那么CMD后的字符串将使用/bin/sh -c执行。

更多的信息可以在Dockerfile参考的CMD部分中找到。


这是我粘贴错误消息时谷歌上的第一个结果,这是因为我的参数顺序不对。

容器名必须在所有参数之后。

Bad:

docker run <container_name> -v $(pwd):/src -it

好:

docker run -v $(pwd):/src -it <container_name>

我也发现了同样的问题。我做了以下事情:

docker run -ti devops -v /tmp:/tmp /bin/bash

当我把它改成

docker run -ti -v /tmp:/tmp devops /bin/bash

它工作得很好。


出现这样的错误有几种可能的原因。

在我的例子中,这是由于可执行文件(docker-entrypoint.sh来自鬼博客Dockerfile)在我下载后缺乏可执行文件模式。

解决方法:chmod +x docker-entrypoint.sh


为了让它工作,在/usr/bin中添加软引用:

Ln -s $(哪个节点)/usr/bin/node

Ln -s $(npm) /usr/bin/npm


出于某种原因,除非我添加了“bash”澄清符,否则我会得到这个错误。甚至加上“#!”“/bin/bash”到我的入口点文件的顶部并没有帮助。

ENTRYPOINT [ "bash", "entrypoint.sh" ]

Docker容器可以在没有shell的情况下构建(例如https://github.com/fluent/fluent-bit-docker-image/issues/19)。

在这种情况下,你可以复制一个静态编译的shell并执行它。

docker create --name temp-busybox busybox:1.31.0
docker cp temp-busybox:/bin/busybox busybox
docker cp busybox mycontainerid:/busybox
docker exec -it mycontainerid /bin/busybox sh

我也有同样的问题,在谷歌上搜索了很多次后,我不知道如何解决它。

突然我发现我犯了个愚蠢的错误:)

正如文档中提到的,docker run的最后一部分是加载容器后要运行的命令及其参数。

不是容器名!!

这是我的尴尬错误。

下面我为您提供了我的命令行图片,以查看我做错了什么。

这就是文档中提到的修复。


在错误信息中显示:

无法启动容器foo_1: \ exec: "grunt serve":在$PATH中找不到可执行文件

它抱怨它无法找到可执行的grunt service,而不是它无法找到带有参数serve的可执行grunt。对于这个特定的错误,最可能的解释是使用json语法运行命令:

[ "grunt serve" ]

在你的合成文件中。这是无效的,因为json语法要求您拆分通常由shell在每个空格上拆分的每个参数。例如:

[ "grunt", "serve" ]

另一种可能的方法是在docker run命令中将它们引用到一个参数中。

docker run your_image_name "grunt serve"

在这种情况下,你需要删除引号,这样它就可以作为单独的参数传递给run命令:

docker run your_image_name grunt serve

对于其他人来说,未找到可执行文件意味着Linux看不到您试图在容器中使用默认$PATH值运行的二进制文件。这可能意味着有很多可能的原因,下面是一些:

Did you remember to include the binary inside your image? If you run a multi-stage image, make sure that binary install is run in the final stage. Run your image with an interactive shell and verify it exists: docker run -it --rm your_image_name /bin/sh Your path when shelling into the container may be modified for the interactive shell, particularly if you use bash, so you may need to specify the full path to the binary inside the container, or you may need to update the path in your Dockerfile with: ENV PATH=$PATH:/custom/dir/bin The binary may not have execute bits set on it, so you may need to make it executable. Do that with chmod: RUN chmod 755 /custom/dir/bin/executable The binary may include dynamically linked libraries that do not exist inside the image. You can use ldd to see the list of dynamically linked libraries. A common reason for this is compiling with glibc (most Linux environments) and running with musl (provided by Alpine): ldd /path/to/executable If you run the image with a volume, that volume can overlay the directory where the executable exists in your image. Volumes do not merge with the image, they get mounted in the filesystem tree same as any other Linux filesystem mount. That means files from the parent filesystem at the mount point are no longer visible. (Note that named volumes are initialized by docker from the image content, but this only happens when the named volume is empty.) So the fix is to not mount volumes on top of paths where you have executables you want to run from the image. If you run a binary for a different platform, and haven't configured binfmt_misc with the --fix-binary option, qemu will be looking for the interpreter inside the container filesystem namespace instead of the host filesystem. See this Ubuntu bug report for more details on this issue. If the error is from a shell script, the issue is often with the first line of that script (e.g. the #!/bin/bash). Either the command doesn't exist inside the image for a reason above, or the file is not saved as ascii or utf8 with Linux linefeeds. You can attempt dos2unix to fix the linefeeds, or check your git and editor settings.


问题是glibc,它不是apline基映像的一部分。

添加后,它为我工作:)

下面是获得glibc的步骤

apk --no-cache add ca-certificates wget
wget -q -O /etc/apk/keys/sgerrand.rsa.pub https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub
wget https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.28-r0/glibc-2.28-r0.apk
apk add glibc-2.28-r0.apk

指标题。

我的错误是在docker运行期间通过——env-file放置变量。在其他文件中,该文件包含一个PATH扩展名:PATH=$PATH:something,这导致PATH var看起来像PATH=$PATH:something (var解析没有执行),而不是PATH:/usr/bin…:something。

我不能使决议工作通过- ENV -file,所以我看到这个工作的唯一方式是通过使用Dockerfile中的ENV。


我在使用docker-compose时遇到了这个问题。这里或这个相关问题的解决方案都不能解决我的问题。最终对我有用的是用docker prune -a和重新启动docker来清除所有缓存的docker工件。


我得到了这个错误信息,当我建立阿尔卑斯山基地图像:

ERROR: for web  Cannot start service web: OCI runtime create failed: container_linux.go:380: starting container process caused: exec: "bash": executable file not found in $PATH: unknown

在我的docker-compose文件中,我有一个命令指令,其中使用bash和bash执行命令时不附带alpine基本映像。

command: bash -c "python manage.py runserver 0.0.0.0:8000"

然后我用sh (shell)实现并执行了命令。 这对我很管用。


在我的情况下,我命令参数错误移动所有开关之前的图像名称