在 docker 容器中找不到 vue

vue not found in docker container

我正在尝试 运行 vue/cli 在 docker 容器中。
我启动容器通过docker exec -it命令进入容器的cli,输入命令npm install @vue/cli。现在,当我看到容器的 package.json 文件时,我看到安装了包,但是当我尝试使用命令 vue create <project-name> 创建项目时,它显示 vue command not found.

{
  "name": "node_dock_2",
  "version": "1.0.0",
  "description": "node with docker with vue.js",
  "main": "index.js",
  "scripts": {
    "start": "node index.js"
  },
  "keywords": [
    "website",
    "Docker",
    "vue.js",
    "vue/cli"
  ],
  "author": "Viraj",
  "license": "ISC",
  "dependencies": {
    "@vue/cli": "^4.5.15",
    "express": "^4.17.2"
  }
}

这是我尝试安装@vue/cli时的消息:(npm install @vue/cli)

up to date, audited 943 packages in 12s

68 packages are looking for funding
  run `npm fund` for details

14 vulnerabilities (6 moderate, 8 high)

To address issues that do not require attention, run:
  npm audit fix

Some issues need review, and may require choosing
a different dependency.

Run `npm audit` for details.

这是我的Dockerfile(Dockerfile,index.js和package.json在同一个目录)。

FROM node
WORKDIR /
COPY . .
RUN npm install
CMD ["node", "/index.js"]

我做错了什么?

从错误来看,您的容器似乎没有正确的 PATH 来查找 vue 二进制文件

PATH variable

It's essentially a : separated list of directories. When you execute a command, the shell searches through each of these directories, one by one, until it finds a directory where the executable exists

首先使用 -g 选项全局安装 vue/clie

npm install -g @vue/cli

附加到容器的现有 PATH 变量以包含 /root/.npn-global/bin 文件夹。这将允许系统找到 vue 二进制文件

export PATH=$PATH:/root/.npm-global/bin 

您应该相应地更新您的 Dockerfile 以使这些更改永久生效。