简体   繁体   English

我正在尝试从一个小项目的图像创建一个容器,但我收到一个错误:docker: 来自守护进程的错误响应

[英]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.

相关问题 我正在尝试从堆栈创建队列,但出现错误“找不到所需的变量” - I m trying to create a queue from stacks but I get the error “Can't find the variable require” 我正在尝试从 base64 获取图像的高度 - I'm trying to get the height of the image from base64 我正在尝试从父容器中获取所有按钮ID,并始终获取最后一个 - I'm Trying to get all button id's from a parent container and always get the last one 我正在尝试显示从本地服务器获取的数据,但收到错误消息 - I'm trying to display data that i fetched from my local server but I receive an error React Native:尝试从 Cloud Firestore 获取图像时出现错误 - React Native: I am getting error while trying to get image from cloud firestore 尝试将从服务器获取的 HTML 代码转换为 Image ,但在 ReactJS 中出现错误 - Trying to convert HTML code that I get from server to Image , but gives me an error, in ReactJS 我正在尝试从mysql数据库在网页上放置图形我遇到一个错误$未定义如何解决? - I,m trying to put graph on webpage from mysql database I'm getting one error $ is not defined How can i fix it? 如何从 JavaScript 获取响应头错误? - How can I get the response header error from JavaScript? 我试图从 ES 类参数创建一个数组,但我得到一个空数组,为什么? - I'm trying to create an array from ES class arguments but I'm getting an empty Array, why? heroku docker 未找到捆绑包错误//我正在尝试将 dockerfile 部署到 Z3115FB34DFCB5BA873349707 捆绑包但未找到 - heroku docker bundle not found error // i'm trying to deploy dockerfile to heroku but it always says me bundle not found
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM