0

I am currently setting up a Docker container that will be used to Debug a NodeJS application. This container needs to support live-reloading (using nodemon) and needs to be a Linux container (my workstation is a Windows machine).

My current setup is the following:

Dockerfile.debug

FROM node:current-alpine

VOLUME /app

WORKDIR /app

COPY package*.json ./
RUN npm ci --only=production --registry=http://172.16.102.123:8182/repository/npm/

RUN npm install -g nodemon

ENV NODE_ENV=test

EXPOSE 8000
EXPOSE 9229

CMD [ "nodemon", "--inspect=0.0.0.0:9229", "--ignore", "dist/test/**/*.js", "dist/index.js" ]

docker-compose.yml

version: '3'
services:
    app:
        build:
            context: .
            dockerfile: Dockerfile.debug
        volumes:
            - .:/app
            - /app/node_modules
        ports:
            - 8000:8000

Everything works fine except the dependencies because some of these are plattform specific. That means, it is not possible to simply mount the node_modules directory into the container (like I do with the rest of the codebase). I tried setting up my files in such a way, that the dependencies are different for each platform but I either end up with an empty node_modules directory or with the node_modules directory from the host (the current set up gives me an empty directory). Does anybody know how to fix my problem? I have looked at other solutions (like this one) but they did not work.

Lehks
  • 1,230
  • 1
  • 9
  • 26
  • Why does this have to be in Docker, or specifically use Linux? The `VOLUME` statement in your Dockerfile is liable to cause trouble and in particular the combination of things you have here seems likely to give you a completely empty `node_modules` tree, both in the image and at runtime. What's the specific error you're getting? – David Maze Sep 18 '20 at 14:26
  • Docker is used to deploy the application to production and the debugging environment should be as close as the production environment as possible. The error I get is that node can not find any modules because node_modules is empty. – Lehks Sep 21 '20 at 05:15
  • The `volumes:` you have there mean you're not running the code in the image at all: that container has almost no relation to what you'd be running in production. – David Maze Sep 21 '20 at 11:37
  • I am aware of that. But the JavaScript Code itself is platform independent. What is important is that the node executable is running in a Linux environment. But to be honest, it does not really matter why I do this, all I need is to know how I do it. – Lehks Sep 21 '20 at 11:40

0 Answers0