vscode-remote-release icon indicating copy to clipboard operation
vscode-remote-release copied to clipboard

devcontainer support for docker compose watch (new in v2.22 of docker compose)

Open tommysullivan opened this issue 2 years ago • 4 comments

Docker v2.22 now has watch capability. But devcontainer would need to call docker compose watch instead of whatever it does today (up?).

This would simplify my Dockerfiles and eliminate the need to mount volumes or deal with node_modules syncing, especially when native packages may differ between the container and the vs code host machine.

tommysullivan avatar Oct 14 '23 05:10 tommysullivan

This sounds like it would automatically rebuild the dev container when a file change is detected. This would disconnect VS Code from the VS Code Server running in the dev container. When the VS Code Server is stopped only reloading the VS Code window would reconnect to the dev container and restart the server.

chrmarti avatar Dec 07 '23 10:12 chrmarti

This sounds like it would automatically rebuild the dev container when a file change is detected. This would disconnect VS Code from the VS Code Server running in the dev container. When the VS Code Server is stopped only reloading the VS Code window would reconnect to the dev container and restart the server.

If you read the Action section you will see that it does not automatically rebuild the container, that would definitely defeat the purpose.

The sync mode is what we would use here. Instead of manually volume mounting our host filesystem's codebase in, we would allow docker to do that on our behalf. It gives us an instant file sync with no image rebuilds or container restarts. Thats what we want when developing, its just that we no longer have to mount the volumes ourselves. Docker compose will do its own way of syncing for us.

So the ask here is to modify devcontainer to take advantage of that capability by enabling it with the option to call watch instead of up when desired.

Since the container continuously runs, the vs code server will stay running within it the entire time.

tommysullivan avatar Dec 07 '23 21:12 tommysullivan

Any progress on this?

danielpettycognizant avatar Feb 06 '24 17:02 danielpettycognizant

From reading the documentation I get the impression that its main usage is for copying file changes from the host filesystem to the container. With Dev Containers VS Code makes the changes to the files inside the container. Would these changes be copied back to the host filesystem by Docker Compose?

chrmarti avatar Feb 08 '24 10:02 chrmarti

Another common use case would be for compose files with multiple services. VS Code is attached to a dev service, and then a second service running a server component can utilize docker compose watch to sync, restart, or rebuild itself when certain changes are detected.

This would enhance functionality because not every type of change can be handled with a volume and hot reload. Many changes require rebuilding the service, restarting the main process in the service, etc. This currently involves a custom solution or needlessly rebuilding the entire dev container

a13o avatar Feb 24 '24 14:02 a13o

I am currently having issues in vite, the problem for me is that my dev containers use volumes and so it seems that docker doesn't seem to alert vite of any file changes so hot module reloading doesn't seem to work.

According to this: https://syntackle.com/blog/the-issue-of-watching-file-changes-in-docker/

Implementing watch for dev containers would fix this.

The alternative workaround for me right now is to run: inotifywait -m -e modify "." in the components directory. For some reason it still doesn't appear to work with the -r (recursive) flag so I literally need to use it manually in the required dir.

Alternatively I could bake it into each of my directories in the post build script but that really sucks!!

TheDevelolper avatar Mar 29 '24 11:03 TheDevelolper

I am currently having issues in vite, the problem for me is that my dev containers use volumes and so it seems that docker doesn't seem to alert vite of any file changes so hot module reloading doesn't seem to work.

According to this: https://syntackle.com/blog/the-issue-of-watching-file-changes-in-docker/

Implementing watch for dev containers would fix this.

The alternative workaround for me right now is to run: inotifywait -m -e modify "." in the components directory. For some reason it still doesn't appear to work with the -r (recursive) flag so I literally need to use it manually in the required dir.

Alternatively I could bake it into each of my directories in the post build script but that really sucks!!

In the end I solved my hmr hot reload issues. I documented the fix here:

https://dev.to/simplifycomplexity/solving-hot-reload-issues-in-vs-code-dev-containers-on-windows-with-wsl2-16d5

Hope this helps anyone else having the same issues.

TheDevelolper avatar Apr 01 '24 21:04 TheDevelolper

From reading the documentation I get the impression that its main usage is for copying file changes from the host filesystem to the container. With Dev Containers VS Code makes the changes to the files inside the container. Would these changes be copied back to the host filesystem by Docker Compose?

I would be using this to (re)configure separate service containers with changes from the source folder. That is, I have "dockerComposeFile": "docker-compose.yml" set in my main devcontainer config and in docker-compose.yml I've got several databases, messaging brokers and proxies that would benefit from being automatically rebuilt or reconfigured if I change their config in the main source tree, rather than having to rebuild the entire set.

DavidS-ovm avatar Apr 05 '24 12:04 DavidS-ovm