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

Add simple restart action (without sync) to Compose Watch for use with bind mounts #11446

Closed
binaryfire opened this issue Feb 1, 2024 · 8 comments · Fixed by #12375
Closed
Labels
area/watch Related with watch feature kind/feature

Comments

@binaryfire
Copy link

binaryfire commented Feb 1, 2024

Hi guys

We use bind mounts for local development, and there are still times when you need to restart the container on file changes. Laravel's queue workers are a good example - they need to be restarted to pick up on changes and there's no simple way to automate that without a package and some custom code.

Currently there's no Compose Watch action that covers this scenario. sync+restart expects a target that it can sync files to. Would it be possible to add a simple restart action that can just watch files at a given path and restart the container if anything changes? This would make our (and I'm sure many other people's) lives much easier. I'm assuming this would be pretty easy to add: the functionality is there, it's just currently always coupled to a sync?

PS. This has been requested before here: #11062 (comment)

@ndeloof
Copy link
Contributor

ndeloof commented Feb 13, 2024

Why not use sync+restart to replace your bind mount then?
watch actually check there's no conflicting bind mount, which (use to) demonstrate a configuration mistake

@binaryfire
Copy link
Author

binaryfire commented Feb 13, 2024

We have a single image for local development that has Node/PHP/Python/etc. installed and doesn't contain any app data. We use that image + command: to run multiple services in local development by bind-mounting /workdir to different repositories. Many of these services are not containerized in production so Docker is only used in local development for these. Also, several repos are massive and contain huge files that change regularly - sync wouldn't be as performant.

We're quite happy with our setup. All of the recent communication from Docker has been about making the local development experience better. Shouldn't that include supporting how different teams work rather than trying to switch everyone from bind mounts to sync? I don't really understand the downside of adding a standalone restart option. Is there a reason to avoid it other than trying to discourage the use of bind mounts?

@ndeloof
Copy link
Contributor

ndeloof commented Feb 14, 2024

My question is not to reject this feature request, but to better understand which use-cases this would cover, and the benefits for our users.

@binaryfire
Copy link
Author

Ah ok, sorry. I misunderstood.

Hopefully my description explains our use case.

@phill4y
Copy link

phill4y commented Mar 7, 2024

I agree with @binaryfire that this would be really helpful. I stumbled across the same issue a few weeks back and would really like to have an option where I can simply restart the command specified in the docker-compose.yml if a mounted file in a given directory changes.

I am currently using multiple docker images that run some Python scripts which are bind-mounted and the sync+restart takes quite some time which could be avoided that way

@ruscon
Copy link

ruscon commented Apr 8, 2024

@ndeloof
I also came to the idea that it would be nice to be able to restart containers.

We have this case:
Locally we use docker compose and bind the ~/.aws folder to many containers.
Naturally, you can’t put this in a Dockerfile.
But I would like to be able to restart containers if something has changed in the ~/.aws folder

sync+restart do not work as expected with docker secrets because they are bound under the root user, but the process can be launched from another user (I haven’t found a way to bypass this)

@pzavolinsky
Copy link

+1 I'd also love to see this implemented @ndeloof.

Watch is awesome as it is and rebuild when your external dependencies change is key.

That being said, being able to just restart containers without sync means we could roll this out without any major changes to our Dockerfiles (i.e. no need to change existing and working bind mounts for COPY statements) or our workflows (potentially impacting our developer experience).

restarts means we could just change the compose file push and everyone would be up and running without even a container rebuild.

Hope this lands soon! And again, thanks for your efforts on this front, it's definitely a pain shared by everyone running compose for development and you were spot on identifying and addressing this.

Cheers!

@pzavolinsky
Copy link

👋 hey @ndeloof thanks for #12375 ! It works like a charm.

We should update the docs at https://docs.docker.com/compose/how-tos/file-watch/ to include restart.

Here's the python config I'm using, just as an example of a typical "restart for code changes, rebuild for dependency changes" setup that we could include in the docs:

    develop:
      watch:
        - action: restart
          path: ./src
        - action: rebuild
          path: dependencies.txt

Hope this helps, and thanks again for this feature, I'm already loving it (prior to this I was contemplating installing nodemon in python to get to some Frankenstein version of watch 🤦 this is much much cleaner and streamlined).

Cheers!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/watch Related with watch feature kind/feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants