[英]I'm trying to create a container from an image of a small project, but I get an error: docker: Error response from daemon
DockerFile DockerFile
FROM node:latest
WORKDIR /app
COPY . .
RUN npm install
EXPOSE 8080
ENTRYPOINT ["nodemon", "server.js"]
Server.js服务器.js
const express = require('express');
const swaggerUi = require('swagger-ui-express');
const app = express();
const userRouter = require('./routes/userRoutes');
const productRouter = require('./routes/productsRoutes');
const swaggerFile = require('./swagger/swagger_output.json');
const PORT = 8000;
app.use('/doc', swaggerUi.serve, swaggerUi.setup(swaggerFile));
app.use(express.json());
app.listen(PORT, () => {
console.log(`Server rodando em: http://localhost:${PORT}`)
});
app.use('/api', userRouter);
app.use('/api/products', productRouter);
The error : docker: Error response from daemon: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: exec: "nodemon": executable file not found in $PATH: unknown.错误: docker:来自守护进程的错误响应:未能创建 shim 任务:OCI 运行时创建失败:runc 创建失败:无法启动容器进程:exec:“nodemon”:在 $PATH 中找不到可执行文件:未知。
The command docker run -d -p 8000:8080 projeto-pratico-api/node命令docker 运行 -d -p 8000:8080 projeto-pratico-api/node
*projeto-pratico-api/node = name of the image *projeto-pratico-api/node = 图像名称
Your main container process is nodemon
, but it's not installed in your image.您的主要容器进程是nodemon
,但它没有安装在您的映像中。 Since a Docker image contains an immutable copy of the application code, it will never change while the container is running, and you don't need a monitoring tool like nodemon
;由于 Docker 镜像包含应用程序代码的不可变副本,因此在容器运行时它永远不会更改,并且您不需要像nodemon
这样的监控工具; just set the main container process to run node
.只需将主容器进程设置为运行node
。
ENTRYPOINT ["node", "server.js"]
# ^^^^ not nodemon
Try installing nodemon from your Dockerfile?尝试从 Dockerfile 安装 nodemon?
Add:添加:
RUN npm install -g nodemon
Full updated Dockerfile:全面更新 Dockerfile:
FROM node:latest
WORKDIR /app
COPY . .
RUN npm install -g nodemon
RUN npm install
EXPOSE 8080
ENTRYPOINT ["nodemon", "server.js"]
Second approach, use node instead of nodemon:第二种方法,使用 node 而不是 nodemon:
FROM node:16
# Create app directory
WORKDIR /usr/src/app
# Install app dependencies
# A wildcard is used to ensure both package.json AND package-lock.json are copied
# where available (npm@5+)
COPY package*.json ./
RUN npm install
# Bundle app source
COPY . .
EXPOSE 8080
CMD [ "node", "server.js" ]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.