-
Notifications
You must be signed in to change notification settings - Fork 5.3k
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
Lifecycle hook doesn't execute when callilng service.Up in the API #12513
Comments
It would be worth checking this to make sure it creates the services properly. https://gist.github.com/maggie44/98d870da0961b61c32f6e55407697f76 |
Thanks, I updated that gist and included a lifecycle hook 'post_start' and verified that the container did not run the lifecycle hook, so something is not right here. |
Not sure if this has something to do with it but just looking through the code from the change to include lifecycle hooks: #12166 It appears as though no changes were made to up.go which might be why the hooks are being ignored, changes were made to start.go and others. |
I assume it is working when using the docker compose binary on the same host (i.e. using docker compose up instead of this custom code)? |
Yes here is the code that I used to test:
The container will run fine but "/root/file.txt" does not exist. If I run |
Try adding
|
Thanks so much, that solved the issue! |
Sorry to reopen, curious if api.DownOptions would also need to have the Project passed in to execute pre_stop hooks? |
Did you try it? I would suspect that if projectName is set then it isn't necessary.
|
Just a quick note: docker/compose is not a library, and despite we have an |
it does. hooks are defined by Project they're not known by the runtime resources - hooks are not a docker engine feature. if you don't pass a Project, no hook will be executed. |
It's a shame it is not available as a library as there is a real need for it. This particular issue has come up as Portainer now uses this approach. It's an understandable change as Portainer used to call a compose binary with exec and parse the stdout response which is of course all kinds of problematic. I will add the caveat to the top of the gist but hoping to pool our resources and testers to establish a working approach. |
I also added a |
It never has been designed to be one. Docker compose is a command line. exec and parse stdout is the recommended way - we offer json formatted output for this purpose. |
Absolutely, trying to get it to work as a library is clunky and a lot of guess work, as well as not being reliable as changes are made to Compose there is no guarantee it won't break. The decision wasn't taken lightly, for my use case I have been back and forth for a year on how best to implement this. Neither approach is perfect, importing the code as a library is unsupported and I don't want to have to support it, so been using But the I also looked at alternative libraries, Podman doesn't have a Go Compose implementation though, In short, I don't want to do it this way, it sucks. But after weighing up all the different options over a long time, right now this is what we seem to be left with. |
If anyone comes up with a better alternative it would be great to hear, I'm still feeling like that might be a better way. |
I've been pounding my head against this and am not sure if I'm not doing something incorrect or if its the codebase but lifecycle hooks don't seem to get executed when calling the API directly. I have the following example code to test this.
Here is a simple compose.yml to test with:
The container gets created but the post_start hook never runs.
Any ideas or am I just calling this wrong?
The text was updated successfully, but these errors were encountered: