docker/compose

[Question] Service lifecycle event hooks

pedro93 opened this issue · 9 comments

I've been digging across the docker-compose documentation and found the following page regarding container event streaming.

My question is, given that it is possible to be alerted about a container hitting lifecycle stages (created, started, restarts, stops etc ...), full list here, it is possible with docker-compose to listen for such service events and perform an arbitrary script at each stage, such that, that hook pauses the docker-compose process?

As an example, let's say I have an orchestration between two services A, B where B depends on A being healthy. Additionally, service A needs to know some information about B which is dynamically generated on service bootup.

The solution I am looking is some form of before entry point on service B, halt the docker-compose up process so that I can, in the host retrieve the dynamic information from A, generate a bash script with that information, execute the script on service B and then proceed with the docker-compose process.

Thank you for maintaining this project, it is extremely useful :)

Edit: Updated last paragraph, mixed up the service order, my apologies

shin- commented

See our recommendation here: #2392
And the wider discussion on this feature here: #1341

Thank you, I have commented on the linked issue.

shin- commented

Out of curiosity, why can't that provisioning be part of your entrypoint script?

Because the entrypoint script is defined in the host and executed in the container (this case service B) but the information I would need to add to the entrypoint script is generated in the runtime of service A.

Does that make it clearer?

shin- commented

It seems like B's entrypoint could make a request to A for that information. Not only would that work with the current tool, it would ensure that if B crashes and needs to restart, it's able to retrieve the information again without any intervention by the Compose process.

Thank you @shin- for the assistance, I agree with you that that particular approach would work, but you are assuming one key thing, that the information from A is accessible from an endpoint. Unfortunatly this is not the case and it is not in my power to change it.

About #2392 correct me if I am wrong but the event listening does not actually pause the docker-compose process right?

shin- commented

I see. Sorry I couldn't be of help.

And no, docker-compose events doesn't pause the process.

Thank you regardless 😄 you may close the issue. I will have to find some other tool for my particular needs.

+1 on the project.