Mr.Singh
Mr.Singh

Reputation: 1789

Docker: Nodemon is syncing but not re-running

I am new at Docker.

The files are syncing upon changes using the bind mount, but the nodemon is not re-running. To see the changes, I have to stop the container and restart using docker compose up.

I tried so many solutions but the problem still remains.

Dockerfile

FROM node:18-alpine3.17
WORKDIR /app
COPY package*.json /app
RUN npm ci
COPY . /app
EXPOSE 3000
# CMD [ "npm", "run", "dev" ]

docker-compose.yml

version: "3.9"

services:
  frontend:
    build:
      context: .
      dockerfile: Dockerfile
    command: npm run dev
    container_name: study-001-frontend-reactjs
    networks:
      - study-001
    ports:
      - 3000:3000
    volumes:
      - .:/app
      - /app/node_modules

networks:
  study-001:

package.json

{
    "name": "001-study",
    "version": "1.0.0",
    "description": "",
    "main": "index.js",
    "type": "module",
    "scripts": {
        "test": "echo \"Error: no test specified\" && exit 1",
        "dev": "nodemon index.js"
    },
    "keywords": [],
    "author": "",
    "license": "ISC",
    "dependencies": {
        "express": "^4.18.2"
    },
    "devDependencies": {
        "nodemon": "^2.0.20"
    }
}

enter image description here

git repo:

Everything is working fine if I am running the project without using Docker.

What am I missing..?

Git repository: https://[email protected]/pammysayshello/docker-issue.git

Upvotes: 0

Views: 174

Answers (1)

Wahinya Brian
Wahinya Brian

Reputation: 1001

I suspect the nodemon is not being installed correctly in the docker container.

Try this

:

docker-compose.yml: remove the volume /app/nodemodules.

volumes:
  - .:/app

Dockerfile:

try using npm i instead of npm ci.

RUN npm install

Change copy package*.json ./app to package*.json ./

COPY package*.json ./

Already you have declared a workdir as /app so replace copy . /app with copy . .

COPY . .

Finally kill the container, delete the image and execute docker-compose up again

Upvotes: 0

Related Questions