Docker CMD不';看不到已安装的组件

Docker CMD不';看不到已安装的组件,docker,dockerfile,Docker,Dockerfile,我正在尝试使用以下docker文件构建docker映像 FROM ubuntu:latest # Replace shell with bash so we can source files RUN rm /bin/sh && ln -s /bin/bash /bin/sh # Update packages RUN apt-get -y update && apt-get install -y \ curl \ build-essentia

我正在尝试使用以下docker文件构建docker映像

FROM ubuntu:latest

# Replace shell with bash so we can source files
RUN rm /bin/sh && ln -s /bin/bash /bin/sh

# Update packages 
RUN apt-get -y update && apt-get install -y \
    curl \
    build-essential \
    libssl-dev \
    git \
    && rm -rf /var/lib/apt/lists/*

ENV APP_NAME testapp
ENV NODE_VERSION 5.10
ENV SERVE_PORT 8080
ENV LIVE_RELOAD_PORT 8888

# Install nvm, node, and angular
RUN (curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.31.1/install.sh | bash -) \
    && source /root/.nvm/nvm.sh \
    && nvm install $NODE_VERSION \
    && npm install -g angular-cli \
    && ng new $APP_NAME \
    && cd $APP_NAME \
    && npm run postinstall

EXPOSE $SERVE_PORT $LIVE_RELOAD_PORT

WORKDIR $APP_NAME

EXPOSE 8080

CMD ["node", "-v"]
但在尝试运行它时,我一直会出错:

docker: Error response from daemon: Container command 'node' not found or does not exist..
我知道节点安装正确,因为如果我通过注释docker文件中的CMD行来重建图像

#CMD ["node", "-v"]
然后启动一个shell会话

docker run -it testimage
我可以看到我的所有依赖项都在那里,并返回正确的结果

node -v
v5.10.1


所以我的问题是。为什么Dockerfile中的CMD无法运行这些文件,我如何修复它?

当使用shell通过nvm运行节点时,您已经获取了
nvm.sh
文件,它将在其环境中设置一个
$PATH
变量,以便通过nvm搜索可执行文件

当您通过
docker run
运行命令时,它只会


由于其工作方式,最好使用节点二进制文件而不是
nvm
helper脚本。在docker中使用而不是nvm可能更容易。

当使用shell通过nvm运行
节点
时,您已经获取了
nvm.sh
文件,它将在其环境中设置一个
$PATH
变量,以便通过nvm搜索可执行文件

当您通过
docker run
运行命令时,它只会

由于其工作方式,最好使用节点二进制文件而不是
nvm
helper脚本。使用in-docker可能比使用nvm更容易

ng -v
angular-cli: 1.0.0-beta.5
node: 5.10.1
os: linux x64
docker run <your-ubuntu-image> echo $PATH
docker run <your-ubuntu-image> which node
docker run <your-ubuntu-image> nvm which node
CMD ["/bin/node","-v"]