Docker Compose not synchronising file changes in volume
0
votes
0
answers
545
views
Reposting from [here](https://forums.docker.com/t/docker-compose-not-synchronising-file-changes-in-volume/79177) as I don't quite understand how the "solution" works.
**Symptom:**
As reported [here](https://forums.docker.com/t/docker-compose-not-synchronising-file-changes-in-volume/79177) :
I mount my local files into the container for development. My
docker-compose.yml
file is as follows:
version: '3.7'
services:
node:
build: .
command: npm run dev
image: node
ports:
- "4000:3000"
volumes:
- .:/code
working_dir: /code
when I run the Next JS server in a container, it will initially load fine, but any changes made afterwards will not be shown.
This is same as my observation as well.
**Answers:**
There has been discussion on the issues of running docker in Windows 10 Pro, but I'm hosting in Linux for Linux, and the "solution" mentioned nothing about Windows either.
**Solution:**
The reported working "solution" is:
version: '3.7'
services:
node:
build: .
command: npm run dev
image: node
ports:
- "4000:3000"
volumes:
- type: bind
source: .
target: /code
working_dir: /code
This, to my knowledge, would be the same as what used by OP, i.e.:
volumes:
- .:/code
I.e., I think the question of why _"docker Compose not synchronising file changes in volume"_ was not clearly answered. And neither of the following pages:
- https://stackoverflow.com/questions/44678042/named-docker-volume-not-updating-using-docker-compose
- https://stackoverflow.com/questions/44251094/i-want-to-share-code-content-across-several-containers-using-docker-compose-volu/44265470
- https://stackoverflow.com/questions/42958573/docker-compose-recommended-way-to-use-data-containers
My case:
I have a php site hosted on nginx:
version: '3.7'
services:
web:
image: nginx:latest
ports:
- "80:8081"
volumes:
- ./nginx.conf:/etc/nginx/conf.d/default.conf:delegated
- ./app:/app:delegated
php:
build:
context: .
dockerfile: PHP.Dockerfile
volumes:
- ./app:/app:delegated
restart: always
This is my observation:
- I do docker compose up
- Then ^-C to stop it
- Update code in host,
- Re- do / start docker compose up
- Check the modified volume-mounted file within docker compose container,
- The file stays the same, as before the change.
Asked by xpt
(1858 rep)
Aug 15, 2024, 02:01 PM
Last activity: Aug 15, 2024, 02:06 PM
Last activity: Aug 15, 2024, 02:06 PM