I’m new to docker world and migrating a spring boot application to run in docker container. This application has a singleton task that performs these steps.
- Updates task status as active in db (to prevent other instances from running the same task)
- Executes long running business logic (could take up 20-30 min)
- At the end of business processing, updates the task status to complete.
It is possible for this task to crash (e.g. process got killed/power failures) while executing the business logic leaving a stale task status entry behind. During restart, the application checks for stale task status entries associated with this server instance and applies required recovery logic so subsequent
task triggers can run.
In the non-container world, we had assigned a unique identifier to JVM arg to each server instance so task status entry can be associated with a server instance to control the singleton task execution and restart/recovery.
In docker world, scale is used to create multiple instances. Is there a way for an instance to query its instance ID assigned by the container? If not, is there a way to pass a unique identifier during startup?
Pivotal cloud foundry assigns unique instance identifier to environment variable CF_INSTANCE_INDEX that application could use for this purpose and wondering if there is anything similar that docker provides.
Any help/insight would be much appreciated.