[英]Docker - /bin/sh: nodemon: not found
I have the following docker file.我有以下 docker 文件。
#Dockerfile
FROM node:alpine
WORKDIR /backend
COPY package*.json .
RUN yarn
COPY . .
EXPOSE 5000
CMD ["yarn", "dev"]
Nodemon works as intended on host machine but shows the following error message when running the container. Nodemon 在主机上按预期工作,但在运行容器时显示以下错误消息。
yarn run v1.22.5
$ nodemon
/bin/sh: nodemon: not found
error Command failed with exit code 127.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Nodemon is not installed globally in the host machine. Nodemon 未全局安装在主机中。 Adding
RUN yarn add global nodemon
on Dockerfile just adds an extra warning../package.json: No license field
in the container error.在 Dockerfile 上添加
RUN yarn add global nodemon
只会添加一个额外的warning../package.json: No license field
in the container 错误。
I currently have the following package.json file with the following dev dependencies我目前有以下 package.json 文件,其中包含以下开发依赖项
# package.json
...
"scripts": {
"build": "tsc -p .",
"start": "node ./dist/src/index.js",
"dev": "nodemon",
"test": "echo \"Error: no test specified\" && exit 1"
},
"devDependencies": {
"@types/express": "^4.17.11",
"@types/node": "^14.14.34",
"nodemon": "^2.0.7",
"ts-node": "^9.1.1",
"typescript": "^4.2.3"
},
...
and nodemon.json as和 nodemon.json 为
{
"watch": [
"src"
],
"ext": "ts,json",
"ignore": [
"src/**/*.spec.ts"
],
"exec": "yarn ts-node src/index.ts"
}
Try with below,试试下面,
#Dockerfile
FROM node:alpine
WORKDIR /backend
COPY package*.json .
RUN yarn
RUN yarn add global nodemon
COPY . .
EXPOSE 5000
CMD ["yarn", "dev"]
SIDE NOTE: You better not using nodemon
in production.旁注:您最好不要在生产中使用
nodemon
。 Serve build files as in your start
script.像在
start
脚本中一样提供构建文件。 You have to add the build command before yarn start.您必须在纱线启动之前添加构建命令。
#Dockerfile
FROM node:alpine
WORKDIR /backend
COPY package*.json .
RUN yarn
COPY . .
RUN yarn run build
EXPOSE 5000
CMD ["yarn", "start"]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.