How to avoid Docker container deletion after build completion

お困りですか?

アトラシアン コミュニティをご利用ください。

コミュニティに質問

プラットフォームについて: Server および Data Center のみ。この記事は、Server および Data Center プラットフォームのアトラシアン製品にのみ適用されます。

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.

*Fisheye および Crucible は除く

要約

When running containers through Docker Tasks in Bamboo, by default, all containers created during a Bamboo Job execution will be deleted after its completion. Depending on your use-case scenario, you might want to keep the containers running after the build completes, for troubleshooting purposes for example. This article will go through the steps to achieve that.

環境

Bamboo Build Plans with Docker Tasks.

診断

The log snippet below shows that the container is run by the Docker Task, but gets removed by the post-build plugin Docker Container Cleanup after the job finishes.

simple	24-May-2022 18:41:36	Starting task 'Docker run' of type 'com.atlassian.bamboo.plugins.bamboo-docker-plugin:task.docker.cli'
simple	24-May-2022 18:41:36	Running image name (busybox:latest)
[...]
build	24-May-2022 18:41:36	16fc6cb175c44457c8c059f30674b18d30a3463d4bdebc7d807f5b1826e21b0c
simple	24-May-2022 18:41:36	Finished task 'Docker run' with result: Success
simple	24-May-2022 18:41:36	Running post build plugin 'Docker Container Cleanup'


原因

By design, all containers started in the background by the Docker Tasks during the execution of a job will be terminated at the end of the job.

You can use the Detach container checkbox (see below) to start a container in a task in detached mode, and then use that same container in subsequent tasks (e.g., to run tests). However, the container will still be removed once the build job has finished.

Detached container checkbox

The Container name must be unique.
Please note that the job will fail if there's a container already running with the same name. You can use a variable, like ${bamboo.buildNumber}  to work around that.


If you're looking for a way to start a container and keep it running after the Bamboo job and its respective build have been completed, please refer to the Solution section.

ソリューション

Option 1: Script Tasks

Run the Docker command using a Script Task, and add the -d  option for detached execution.

Script Task content
docker run --name=bamboo8 --init -d -p 54663:54663 -p 8085:8085 atlassian/bamboo-server:latest

Option 2: Modify the default behavior of the Docker Plugin bundled with Bamboo

There is a way to disable the "Docker Container Cleanup", which is the post-build plugin that removes the containers. It's a module of the bundled Bamboo Docker Support Plugin that can be disabled through the following steps:

  1. Log in as a Bamboo administrator
  2. Click the "Cog" icon >> "Overview
  3. Open "Manage Apps"
  4. In the drop-down menu, select "All apps"
  5. Search for "Bamboo Docker Support"
  6. Click "4 of 4 modules enabled"
  7. Scroll a little further down to "Docker Container Cleanup"
  8. Click "Disable"

By doing that, the post-build plugin won't be executed anymore, therefore, the containers will not be deleted once the build finishes.

Please note that the container name must be unique. The job will fail if there's a container already running with the same name (e.g., from a previous build run). You can use a variable, like ${bamboo.buildNumber}  to work around that.

最終更新日 2022 年 5 月 24 日

この内容はお役に立ちましたか?

はい
いいえ
この記事についてのフィードバックを送信する
Powered by Confluence and Scroll Viewport.