我有一个安装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部分中找到。

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

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

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

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

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

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

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