DockerFile
FROM node:latest
WORKDIR /app
COPY . .
RUN npm install
EXPOSE 8080
ENTRYPOINT ["nodemon", "server.js"]
Server.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.
The command docker run -d -p 8000:8080 projeto-pratico-api/node
*projeto-pratico-api/node = name of the image
CodePudding user response:
Your main container process is nodemon
, but it's not installed in your image. 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
; just set the main container process to run node
.
ENTRYPOINT ["node", "server.js"]
# ^^^^ not nodemon
CodePudding user response:
Try installing nodemon from your Dockerfile?
Add:
RUN npm install -g nodemon
Full updated Dockerfile:
FROM node:latest
WORKDIR /app
COPY . .
RUN npm install -g nodemon
RUN npm install
EXPOSE 8080
ENTRYPOINT ["nodemon", "server.js"]