dockerdocker-composeweb-development-server

Docker Compose watch for changes inside the container


The watch command allows to automatically update files in the container as they are changed on the host machine. 1

services:
  backend:
    ...
    develop:
      watch:
        - action: sync
          path: .
          target: /var/www

Am I correct in saying that it doesn't work the other way around: changes in target directory in the container will not be reflected in the path on the host machine?

E.g., if I wanted to create logs files inside the container and write them to the project directory on my host machine, would I have to bind volume?


Solution

  • Indeed, you are right. At this moment, sync is 1-way: changes in the host system will be reflected in the container, but not the other way round.

    The sync documentation mentions that files are synced from host to container and that, for most development cases, this can be used instead of bind mounts.

    However, it also says it does not replace bind mounts, so if you need changes inside the container to be propagated back to the host, you would need to use bind mounts.