我有一个安装 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"]
原文由 Steve Lorimer 发布,翻译遵循 CC BY-SA 4.0 许可协议
当您对命令使用 exec 格式时(例如
CMD ["grunt"]
,带有双引号的 JSON 数组),它将在 没有 shell 的情况下执行。这意味着大多数环境变量将不存在。如果您将命令指定为常规字符串(例如
CMD grunt
),则CMD
之后的字符串将使用/bin/sh -c
执行。有关这方面的更多信息,请 参阅 Dockerfile 参考 的 CMD 部分。