J
J
Jesus_newrba2020-02-05 13:30:46
Node.js
Jesus_newrba, 2020-02-05 13:30:46

How to properly implement hot reload in docker?

I'm using Nodemon for hot reload, how do I properly insert it into docker?

Project Structure
5e3a94d393f62015260327.png

With this code, it is only updated when the container is reloaded.
docker-compose.yml

version: "3"
services:
  mongo:
    hostname: mongo
    image: mongo
    restart: always
    volumes:
      - mongodata:/data/db
    ports:
      - "27017:27017"
    logging:
      driver: none
  api:
    build:
      context: api/
      dockerfile: Dockerfile
    environment:
      NODE_ENV: 'production'
      SECRET: 'supersecretword'
      MONGO_HOST: 'mongodb://mongo/app'
      PORT: 3000
    ports:
      - "3000:3000"
    links:
      - mongo
    depends_on:
      - mongo
  app:
    build:
      context: app/
      dockerfile: Dockerfile
    ports:
      - "80:80"
volumes:
  mongodata:


docker-compose.dev.yml

version: "3"
services:
  api:
    build:
      context: api/
      dockerfile: Dockerfile.dev
    environment:
      NODE_ENV: development
      SECRET: 'supersecretword'
      MONGO_HOST: 'mongodb://mongo/app'
      PORT: 3000
    volumes:
      - ./api:/usr/src/api
      - /api/node_modules
  app:
    build:
      context: app/
      dockerfile: Dockerfile.dev
    environment:
      NODE_ENV: development
    volumes:
      - ./app:/usr/src/app
      - /app/node_modules


api\Dockerfile

FROM node:10
WORKDIR /usr/src/api
COPY ./package*.json ./
RUN npm install
COPY . .
RUN npm run build

EXPOSE 3000
CMD ["node", "dist/server.js"]


api\dockerfile.dev

FROM node:10

WORKDIR /usr/src/api

RUN npm install

EXPOSE 3000

CMD ["npm", "run", "start"]


package.json api

"scripts": {
    "start": "nodemon server.js --exec babel-node --presets env"
  }


I run via docker-compose -f docker-compose.yml -f docker-compose.dev.yml up

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
Jesus_newrba, 2020-02-05
@Jesus_newrba

I solved the problem by adding the -L flag for nodemon
https://github.com/remy/nodemon#application-isnt-r...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question