Docker containers are not removed after a build completes
Platform Notice: Data Center - This article applies to Atlassian products on the Data Center platform.
Note that this knowledge base article was created for the Data Center version of the product. Data Center knowledge base articles for non-Data Center-specific features may also work for Server versions of the product, however they have not been tested. Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.
*Except Fisheye and Crucible
Symptoms
When running a non-detached container in Bamboo using the Docker task, and the container fails to start, the Bamboo build will fail but the Docker container is not removed on completion of the task.
The logs may contain an error related to the command being executed inside the container, but it will not hint that the container has not been removed.
Possible excessive disk usage may hint at the problem.
Cause
Non-detached containers are run with the --rm
argument meaning that Docker should remove them when the process exits. However, if the container is unable to start due to misconfiguration of the command to be executed in the container, Docker will not remove it. This is presumably so that the cause of the error can be diagnosed.
Resolution
The leftover containers will not influence subsequent builds so may go unnoticed for some time. If the Docker service on the agent hasn't been restarted in a while this may lead to excessive disk usage. You can reclaim the disk space by manually removing the container using the docker rm
command, for example:
docker rm my-failed-container
Of course, you should also correct any misconfigured container in a failing build.
Note: Feature request opened for the above scenarios BAM-21766 - Option to cleanup container if the Docker task failed to start it