skip to Main Content

I’m learning how to use docker, this is on windows. I have a simple docker compose:

version: "3.8"

services:
  auth:
    container_name: auth
    stdin_open: true
    restart: always
    build:
      context: ./auth
    command: npm run dev
    ports:
      - "3003:3003"
    volumes:
      - ./auth:/usr/src/app/auth
      - /usr/src/app/auth/node_modules

where my run dev inside package.json auth app is:

"dev": "nodemon -L src/index.ts",

upon running and looking at logs:

// inside a route I have a console.log
console.log("GET /signup");


auth    | > [email protected] dev
auth    | > nodemon -L src/index.ts
auth    |
auth    | [nodemon] 2.0.16
auth    | [nodemon] to restart at any time, enter `rs`
auth    | [nodemon] watching path(s): *.*
auth    | [nodemon] watching extensions: ts,json
auth    | [nodemon] starting `ts-node src/index.ts`
auth    | [Auth] Connected to database
auth    | [Auth] Server running on port 3003
auth    | GET /signup   

I test the route and it works. The odd part is changes I make are reset by nodemon but aren’t actually propagated…

changes to the log:

console.log("GET but why /signup");

the container log with route test:

auth    | [nodemon] restarting due to changes...
auth    | [nodemon] starting `ts-node src/index.ts`
auth    | [Auth] Connected to database
auth    | [Auth] Server running on port 3003
auth    | GET /signup

As you can see the console never changed, in fact, I even delete the whole route for sanity, it reset and the route still works even though the code was removed.

What am I missing here?

2

Answers


  1. As was mentioned before, could you provide us with Dockerfile you’re intending to use?

    In general, if changes are not saved after restart you have to look into your volume section in either your Dockerfile or docker-compose.yml .
    In case everything’s fine you’ll have to look into permissions to write on the machine itself and change them in Dockerfile before running.

    Example line from Dockerfile:

    RUN chmod -R 755 *directory with no permission for writing*
    

    The command below to enter container cli:

    docker exec -it *container_id* /bin/bash (or whatever *sh you're using)
    
    Login or Signup to reply.
  2. I think it is an issue with Docker on Windows.

    Please refer to this article to have a fix for this. https://levelup.gitconnected.com/docker-desktop-on-wsl2-the-problem-with-mixing-file-systems-a8b5dcd79b22

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search