Docker compose nodemon development environment wont start

January 25, 2020

ⓘ This article is 1741 days old and may be out of date.

Docker Nodejs develop environment nodemon wont start

When you are using different host architecture for docker(linux) as develop environment for nodejs(windows) you will need create some "docker-compose" like this, some peoples forget if you mount current directory after build docker image the container will mount the node_modules from outside container over the container node_modules folder this will cause your node app run with outside container dependencies, and if you are using dependencies that need architecture specific non js pure modules, like sharp your app will run incorrectly, to fix this we need put the node_modules ignored by the volume with this simple line in docker compose.

# docker-compose.dev.yml

version: "3"

services:
  example-service:
    build: .
    volumes:
      - .:/usr/src/app
      # current folder mounted inside container
      - /usr/src/app/node_modules
      # folder to be ignored by docker volume
      # this are equivalent to say mount node_modules in own node_modules
    ports:
      - 3000:3000
    command: npm start

Now your app will start without problems, if this are the cause of your problem.

$ exit code 0

Vinicios Clarindo
@vinicioslc