无法启动容器进程:exec:“npm”:在$PATH中找不到可执行文件:未知

问题描述 投票:0回答:1

我创建了一个

Dockerfile
,它创建了一个以 Ubuntu 映像为基础的 React 项目,并且在运行容器时出现此错误

docker: Error response from daemon: failed to create task for container: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: exec: "npm": executable file not found in $PATH: unknown.
ERRO[0000] error waiting for container: context canceled

这是

Dockerfile

FROM ubuntu:latest
WORKDIR /app
RUN apt update &&\
    apt-get -y install curl &&\
    curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.0/install.sh | bash &&\
    export NVM_DIR="/root/.nvm" &&\
    [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" &&\
    nvm install --lts &&\
    npm create vite@latest -y . -- --template react-ts &&\
    npm install

EXPOSE 5173
ENTRYPOINT [ "npm", "run", "dev" ]
CMD ["--", "--host"]

我尝试将

npm
node
可执行文件添加到路径变量,但它似乎不起作用。

docker dockerfile
1个回答
0
投票

node:latest
图像开始怎么样?

FROM node:latest

WORKDIR /app

RUN npm create vite@latest -y . -- --template react-ts && \
    npm install

EXPOSE 5173
ENTRYPOINT [ "npm", "run", "dev" ]
CMD ["--", "--host"]

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.