How to access images in private repository using a Bamboo Docker Tasks when the job is running inside a Bamboo Docker Runner (DinD)

お困りですか?

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

コミュニティに質問

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

このナレッジベース記事は製品の Data Center バージョン用に作成されています。Data Center 固有ではない機能の Data Center ナレッジベースは、製品のサーバー バージョンでも動作する可能性はありますが、テストは行われていません。サーバー*製品のサポートは 2024 年 2 月 15 日に終了しました。サーバー製品を利用している場合は、アトラシアンのサーバー製品のサポート終了のお知らせページにて移行オプションをご確認ください。

*Fisheye および Crucible は除く

目的

Docker Runner is a Bamboo feature that allows you to run builds and deployments in a Docker container. This article explains how to pull an image or push an image to the private repository using Bamboo Docker tasks when the job is configured to run inside a Docker Runner

環境

The steps are tested in the following environments, but the solution will be applicable to other Bamboo versions as well:

  • Bamboo Data Centre Version 9.6.1
  • Docker Version 24.0.5
  • Linux Remote Agent

How Bamboo Works with Docker Runner

  • Bamboo starts the docker runner container for executing the job inside a Bamboo agent. 
  • For every task in the job, Bamboo frames a shell script based on the task's configuration inside Bamboo Agent, which is then copied to the Docker Runner for isolated execution.
  • Docker CLI tasks, dependent on the images stored in the private repository need credentials, which are stored in the ~/.docker/config.json file of the Bamboo Agents user's home directory.
  • To avoid conflicts with the other running Bamboo jobs dependent on   ~/.docker/config.json file the folder gets copied to a new file in ~/.dockercfg-bamboo-<agent_UUID> folder.
  • While framing the shell script for Docker tasks, Bamboo adds config parameter (--config) to the docker command with the value .dockercfg-bamboo-<agent_UUID>, which is then copied to the Docker Runner for isolated execution.
  • While using a Docker Task to pull an image from a private repository, you may encounter the below error due to Docker credentials from the host machine were not passed to the Docker Runner container
Error while the Docker Task pull an Image
error    29-Jun-2024 17:47:29    ************************************/privateRepo/TestImage:1.6: pull access denied, repository does not exist or may require authorization: server message: insufficient_scope: authorization failed
  • The below solutions explain how to overcome this situation. 

ソリューション

Scenario 1: While using a remote agent

  1. When configuring the Docker Runner, an additional volume needs to be added along with the default volumes ${bamboo.working.directory} and ${bamboo.tmp.directory}. So that the Docker Runner container can get access to the config.json file available in the Bamboo Remote Agent's user home directory. 
  2. During Docker Runner configuration, add an additional mount volume ${system.HOME}. This way, Docker Runner can access the home directory of the Bamboo Remote Agent host machine.
  3. For running the docker (Docker Task) inside the docker (Docker Runner), the Docker daemon /var/run/docker.sock also needs to be mounted.

Scenario 2:  While using Bamboo Docker Agent

  1. By default, the Bamboo Agent base image bamboo-agent-base uses the home directory as /var/atlassian/application-data/bamboo-agent
  2. When creating the Bamboo Remote Agent Container using a bamboo-agent-base image, mount the volume /var/atlassian/application-data/bamboo-agent as bind volume instead of named volume. 

    docker run -e BAMBOO_SERVER=http://bamboo.mycompany.com/agentServer/ -v /var/atlassian/application-data/bamboo-agent:/var/atlassian/application-data/bamboo-agent -v /var/run/docker.sock:/var/run/docker.sock --name="bambooAgent" --hostname="bambooAgent" -d atlassian/bamboo-agent-base
  3. Configure the Docker Runner agent same as mentioned in Scenario 1.

If the agent is configured to run as a service, then ${system.HOME} may not work. In that case, Add additional volume as below:

    1. Host directory: Home directory of the user running the Bamboo remote agent (eg. /home/bamboouser)
    2. Container directory: Home directory of the user running the Docker Runner container (eg. /root)

For related issues concerning Bamboo Elastic agents, particularly on how to handle tasks when the job is running inside a Bamboo Docker Runner, please refer to the Knowledge Base article titledHow to run Bamboo Data Center Docker Runner Using a Docker Image from a Private Docker Registry with Bamboo Elastic Agents.

最終更新日 2024 年 9 月 18 日

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

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