我有一个安装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"]

当前回答

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

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

解决方法:chmod +x docker-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运行期间通过——env-file放置变量。在其他文件中,该文件包含一个PATH扩展名:PATH=$PATH:something,这导致PATH var看起来像PATH=$PATH:something (var解析没有执行),而不是PATH:/usr/bin…:something。

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

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

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

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

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

当我把它改成

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

它工作得很好。

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

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

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