Docker stack/services

Hi Team, I have a requirement where I want to delete all my docker stacks/services created older than n number of days.

I dont see docker stack or services providing information on the creation date/time. Can someone help me on this?

Thanks in advance.

Regards,
Madhu

A service stores CreatedAt and UpdatedAt:

docker service inspect  ${service name} --format '{{ .CreatedAt}}' # output: 2022-03-15 19:04:36.683243528 +0000 UTC

docker service inspect  ${service name} --format '{{ .UpdatedAt}}' # some format as CreatedAt

You can also get the current state, which will return how many hours the service is running

docker service ps bw_bitwarden --format '{{.CurrentState}}' # output: 
Running x hours ago

This should be sufficient to get the dates and delete the services manualy.

Though, there is no --filter for stacks or services that would filter services depending on date or any docker command that would do that. You might want to develop something to automate the process, if the task is not going to remain a one time action.

Got it. Thanks a lot for that information.