Once the docker run command is executed, the docker container is created unless the return code is 125 meaning that the run command itself failed (https://docs.docker.com/engine/reference/run/#exit-status). Any error that happens after the docker run needs to remove the container during cleanup.
This is fixed by
YARN-5366, which changes how we remove containers. However, that was committed into 3.1.0. 2.8, 2.9, and 3.0 are all affected