docker: executable file not found in $PATH

2019-01-12 18:46发布

I have a docker image which installs grunt, but when I try to run it, I get an error:

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

If I run bash in interactive mode, grunt is available.

What am I doing wrong?

Here is my 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
7条回答
够拽才男人
2楼-- · 2019-01-12 19:23

A Docker container might be built without a shell (e.g. https://github.com/fluent/fluent-bit-docker-image/issues/19).

In this case, you can copy-in a statically compiled shell and execute it, e.g.

docker pull busybox
docker create --name temp-busybox
docker cp temp-busybox:/usr/bin/busybox busybox
docker cp busybox mycontainerid:/bin/busybox
docker exec -it mycontainerid chmod +x /bin/busybox
docker exec -it mycontainerid /bin/busybox sh
查看更多
疯言疯语
3楼-- · 2019-01-12 19:28

There are several possible reasons for an error like this.

In my case, it was due to the executable file (docker-entrypoint.sh from the Ghost blog Dockerfile) lacking the executable file mode after I'd downloaded it.

Solution: chmod +x docker-entrypoint.sh

查看更多
▲ chillily
4楼-- · 2019-01-12 19:30

This was the first result on google when I pasted my error message, and it's because my arguments were out of order.

The container name has to be after all of the arguments.

Bad:

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

Good:

docker run -v $(pwd):/src -it <container_name>
查看更多
我想做一个坏孩纸
5楼-- · 2019-01-12 19:31

When you use the exec format for a command (e.g. CMD ["grunt"], a JSON array with double quotes) it will be executed without a shell. This means that most environment variables will not be present.

If you specify your command as a regular string (e.g. CMD grunt) then the string after CMD will be executed with /bin/sh -c.

More info on this is available in the CMD section of the Dockerfile reference.

查看更多
我只想做你的唯一
6楼-- · 2019-01-12 19:37

For some reason, I get that error unless I add the "bash" clarifier. Even adding "#!/bin/bash" to the top of my entrypoint file didn't help.

ENTRYPOINT [ "bash", "entrypoint.sh" ]
查看更多
疯言疯语
7楼-- · 2019-01-12 19:37

to make it work add soft reference to /usr/bin:

ln -s $(which node) /usr/bin/node

ln -s $(which npm) /usr/bin/npm

查看更多
登录 后发表回答