skip to Main Content

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

2

Answers


  1. 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
    
    Login or Signup to reply.
  2. 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"]
    

    Second approach, use node instead of 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" ]
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search