从节点映像运行docker容器时找不到Npm [英] Npm not found when running docker container from node image
问题描述
# Dockerfile
FROM node:7-alpine
RUN mkdir -p /src/app
WORKDIR /src/app
COPY package.json /src/app/package.json
RUN npm install
COPY . /src/app
EXPOSE 3000
CMD ['npm', 'start']
我正在尝试完成
I'm trying to complete a katacoda.com exercise for Dockerizing nodejs applications with the Dockerfile above. The build completes but running the image quits immediately and in the docker logs I see:
/bin/sh: [npm,: not found
我尝试使用 docker -it nodeapp在交互模式下运行容器/ bin / bash
引发错误 docker:来自守护程序的错误响应:oci运行时错误:container_linux.go:262:启动容器进程导致 exec:\ / bin / bash\:stat / bin / bash:没有这样的文件或目录。
因此,我不确定这里发生了什么。
I tried running the container in interactive mode with docker -it nodeapp /bin/bash
which raised the error docker: Error response from daemon: oci runtime error: container_linux.go:262: starting container process caused "exec: \"/bin/bash\": stat /bin/bash: no such file or directory".
So I'm not sure what is going on here.
推荐答案
它不起作用的原因是单引号
The reason it doesn't work is single quotes
CMD ['npm', 'start']
应该是
CMD ["npm", "start"]
当您不使用双引号时,docker将删除单引号并将命令作为 [npm,start]
When you don't use double quotes, docker will remove the single quotes and process the command as [npm, start]
这就是为什么您看到错误 [npm,
:未找到
That is why you see error [npm,
: not found
这篇关于从节点映像运行docker容器时找不到Npm的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!