docker-json-server icon indicating copy to clipboard operation
docker-json-server copied to clipboard

--watch is not reloading when host file changes

Open devansvd opened this issue 6 years ago • 6 comments

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)

devansvd avatar Mar 13 '18 12:03 devansvd

Any updates?

BrunoQuaresma avatar Jul 15 '18 04:07 BrunoQuaresma

Any updates?

It works, please look at this

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

esmaeilpour avatar Feb 12 '19 15:02 esmaeilpour

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.

fernfernfern avatar Mar 23 '19 09:03 fernfernfern

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 https://github.com/moby/moby/issues/15793#issuecomment-135411504.

This works for me:

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

peter-evans avatar Jun 10 '19 07:06 peter-evans

TL;DR - if you are using windows, do not use WSL2 backend in order for the sync to work. See: https://github.com/docker/for-win/issues/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: https://github.com/docker/for-win/issues/8479

MindaugasBernatavicius avatar Apr 03 '21 22:04 MindaugasBernatavicius

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 

joshuaalex avatar Jul 27 '23 10:07 joshuaalex