Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

--watch is not reloading when host file changes #8

Open
devansvd opened this issue Mar 13, 2018 · 6 comments
Open

--watch is not reloading when host file changes #8

devansvd opened this issue Mar 13, 2018 · 6 comments

Comments

@devansvd
Copy link

I passed the --watch argument.

when db.json file changes in host machine the changes also obviously reflects inside docker container /data/db.json since volume mounted. But it still supplies the old db.json values.

The file is changed Right ?

When Post through curl it works properly. Restarting docker container it works properly.

Changing file directly not working (--watch)

@BrunoQuaresma
Copy link

Any updates?

@esmaeilpour
Copy link

esmaeilpour commented Feb 12, 2019

Any updates?

It works, please look at this

version: '3.6'
services:
  json:
    image: clue/json-server
    volumes:
      - ./json-server:/data/
    command: --watch

@fernfernfern
Copy link

I can't get it to work by passing --watch to the end of the docker run command. But if I run the example with --help it outputs the help so the arguments seem to be passed fine. Very strange.

@peter-evans
Copy link

peter-evans commented Jun 10, 2019

I think the reason this is not working for some is due to the volume mount directly on the db.json file. If you mount on the directory instead it should work. Possibly this has something to do with the way that json-server is writing updates to the file. It might be doing something that is causing the inode bind-mount to break. This is a known issue with file-mounts. See this comment moby/moby#15793 (comment).

This works for me:

docker run -d -p 80:80 -v $PWD/data:/data clue/json-server --watch

@MindaugasBernatavicius
Copy link

MindaugasBernatavicius commented Apr 3, 2021

TL;DR - if you are using windows, do not use WSL2 backend in order for the sync to work. See: docker/for-win#8479

In case you are trying to change the file from a windows box and have json-server automatically sync it and display the correct file - it might not work depending on the docker version you are using and whether you are using WSL2 engine.

I have tried it using docker desktop 3.2.2. It did not work using the Dockerfile from this repo and my own Dockerfile.
It works perfectly well on my ubuntu box - same setup, same commands.

The interesting part is if you do docker exec -it .. /bin/sh you will see that the file actually is updated, however json-server does not pick up the changes when using windows machine. After switching the WSL2 engine off (going back to Hyper-V) it started working perfectly! See: docker/for-win#8479

@joshuaalex
Copy link

joshuaalex commented Jul 27, 2023

services:
reservations:
build:
context: .
dockerfile: ./apps/reservations/Dockerfile
target: development
command: pnpm run start:dev reservations
env_file:
- ./apps/reservations/.env
- .env
ports:
- '3002:3002'
volumes:
- .:/usr/src/app
- /usr/src/app/node_modules
auth:
build:
context: .
dockerfile: ./apps/auth/Dockerfile
target: development
command: pnpm run start:dev auth
env_file:
- ./apps/auth/.env
- .env
ports:
- '3001:3001'
- '4001:4001'
volumes:
- .:/usr/src/app
- /usr/src/app/node_modules
notifications:
build:
context: .
dockerfile: ./apps/notifications/Dockerfile
target: development
command: pnpm run start:dev notifications
env_file:
- ./apps/notifications/.env
ports:
- '3003:3003'
- '4003:4003'
volumes:
- .:/usr/src/app
- /usr/src/app/node_modules
listers:
build:
context: .
dockerfile: ./apps/listers/Dockerfile
target: development
command: pnpm run start:dev listers
env_file:
- ./apps/listers/.env
ports:
- '3005:3005'
volumes:
- .:/usr/src/app
- /usr/src/app/node_modules
review:
build:
context: .
dockerfile: ./apps/review/Dockerfile
target: development
command: pnpm run start:dev review
env_file:
- ./apps/review/.env
ports:
- '3007:3007'
volumes:
- .:/usr/src/app
- /usr/src/app/node_modules
payments:
build:
context: .
dockerfile: ./apps/payments/Dockerfile
target: development
command: pnpm run start:dev payments
env_file:
- ./apps/payments/.env
ports:
- '3004:3004'
volumes:
- .:/usr/src/app
- /usr/src/app/node_modules
chat:
build:
context: .
dockerfile: ./apps/chat/Dockerfile
target: development
command: pnpm run start:dev chat
env_file:
- ./apps/chat/.env
ports:
- '3008:3008'
- '4008:4008'
volumes:
- .:/usr/src/app
- /usr/src/app/node_modules
mongo:
image: mongo
ports:
- 27017:27017
volumes:
- ./.volumes/data/db:/data/db
mongo-express:
image: mongo-express:latest
ports:
- 8081:8081
environment:
- ME_CONFIG_MONGODB_SERVER=mongo
- ME_CONFIG_BASICAUTH_USERNAME=root
- ME_CONFIG_BASICAUTH_PASSWORD=root
restart: always
depends_on:
- mongo
nginx:
image: nginx:latest
ports:
- 3000:80
volumes:
- ./default.conf:/etc/nginx/conf.d/default.conf
restart: always

Thank you for your response but please I need help. Here is my docker compose file but I'm still not getting hot reload. I'm using docker desktop on windows 11 wsl 2 ubuntu distros 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants