node-typescript 应用程序 docker 命令错误

node-typescript application docker command error

我使用打字稿创建了一个节点应用程序。

{
  "name": "my-app",
  "version": "1.0.0",
  "main": "index.ts",
  "author": "",
  "license": "MIT",
  "scripts": {
    "start": "node -r ts-node/register index.ts",
  },
  "dependencies": {
    "@types/express": "^4.17.3",
  },
  "devDependencies": {
    "ts-node": "^7.0.1",
    "typescript": "^3.4.5"
  }
}

目前,我已将以下 docker 文件用于 运行 我的应用程序

FROM node:10
WORKDIR /app
COPY package*.json ./
RUN npm i
COPY . .
EXPOSE 1234
CMD ["npm", "run", "start"]

我想 运行 我的应用程序使用节点命令而不是 npm

FROM node:10
WORKDIR /app
COPY package*.json ./
RUN npm i
COPY . .
EXPOSE 1234
CMD ["node", "-r", "ts-node/register", "index.ts"]

但是它会抛出这样的错误

'egister", "index.ts"]' is not recognized as an internal or external command,
operable program or batch file

ts-node未在WORKDIR环境注册,需要添加相对路径。


CMD ["node", "-r", "./node_modules/ts-node/register", "index.ts"]

如果要运行其他包,需要这样注册路径

# add `/app/node_modules/.bin` to $PATH
ENV PATH /app/node_modules/.bin:$PATH