我有一个安装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容器可以在没有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。

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

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

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

Bad:

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

好:

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

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

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)实现并执行了命令。 这对我很管用。

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