Need cleanup procedure for cancelled jobs

Each job runs a functional test on a set of virtual machines. The jobs are in docker containers. Need to remove them in all cases including job or pipeline cancellation.

As found in docs, after_script is not working for that. Also, it seems our shell script in docker container is just being SIGKILL’ed. Is there a way receive SIGTERM or run cleanup script otherwise?

If there is no such way, it worth mentioning it as well.