This is the documentation for Bamboo 5.8. View this page for the

Unknown macro: {spacejump}

of Bamboo, or visit the latest Bamboo documentation.

The Docker task in Atlassian Bamboo allows you to use Docker images and containers in your Bamboo builds and deployments.

Docker タスクは次の Docker アクションをサポートします。

Remember to define a Docker capability on an agent before you configure a Docker task.

Note that Bamboo requires Docker 1.3.3 or later.See also Getting started with Docker and Bamboo for information about how to manage and run your Bamboo remote agents using Docker. 

Docker イメージをビルドする

指定した Dockerfile に基づいて Docker イメージをビルドします。Dockerfile は、タスクの作業ディレクトリ内の既存のファイルとして提供されてあり、タスク設定で定義される場合があります。

イメージは Docker のローカル イメージ インストール ディレクトリに保存され、ジョブ内においてその後の Docker タスクで使用できます。オプションとして、イメージを作業ディレクトリのファイルに保存した後、ビルド アーティファクトとしてパッケージ化できます。

Bamboo で Docker イメージをビルドするには

  1. Create a new Docker task for the relevant job. See Configuring tasks for details.
  2. タスクの説明を追加すると、タスクの作成理由を思い出すのに役立ちます。
  3. [このタスクを無効化] チェックボックスを使用して、タスクを実行するかどうかを制御します。
  4. Docker イメージのビルドコマンドを選択し、設定を完了します。設定の詳細については、以下をクリックしてください。

リポジトリ

結果として生成されるイメージに適用されるリポジトリ名 (およびオプションのタグ)。次のパターンに従います:

registry.address:port/namespace/repository:tag

Only repository is mandatory.

Dockerfile

既存の Dockerfile (タスクの作業ディレクトリにあります) を使用するか、Dockerfile のコンテンツを指定します。

イメージをビルドする際にはキャッシュを使用しない

By default, Docker will reuse a cached build during the next build. See the Docker documentation.

キャッシュを使用しない...」を選択し、新しいイメージに最後のビルド以降の変更を含むようにします。これにより、パフォーマンスが低下する場合があります。

イメージをファイルとして保存する。

Specify the directory location and file name. Optionally configure a a job artifactto pass it to next stages and deployments.

 

必要に応じて、詳細オプションを指定します。 

環境変数

(Optional)  Additional system environment variables that you want to pass to your build. Note that existing environment variables are automatically available to the executable. You can also include Bamboo global or build-specific variables (see Bamboo variables).
Multiple variables should be separated with spaces. Parameters with spaces must be quoted (e.g JAVA_OPTS="-Xms200m -Xmx700m").

作業サブディレクトリ

(オプション)  Bamboo が実行ファイルを実行する、ジョブのルート ディレクトリに相対的な代替サブディレクトリ。ルート ディレクトリには、ジョブの構成済みソース リポジトリから確認されたものがすべて含まれます。このフィールドを空白のまま残した場合、Bamboo はルート ディレクトリでビルド ファイルを検索します。このオプションは、サブディレクトリ内にビルド スクリプトがあり、実行可能ファイルをそのサブディレクトリ内から実行する必要がある場合に便利です。

 

変更を保存します。

Docker コンテナを実行する

指定したイメージに基づいて Docker コンテナを起動します。

タスクの作業ディレクトリはマウントされ、Docker コンテナの作業ディレクトリとしても使用されます。

既定では、コンテナはタスクの完了時に削除されますが、コンテナのデタッチを選択し、プロジェクトのデプロイメントが完了した後にコンテナを引き続き実行させることができます。「デタッチド コンテナへリンクする」オプションを選択することで、ジョブ内の先行タスクで開始したデタッチド コンテナへと、コンテナをリンクさせることができます。

Note that a non-detached container that fails to start will not be removed when the Bamboo task completes. See this KB article for more details.

Bamboo で Docker コンテナを実行するには:

  1. Create a new Docker task for the relevant job. See Configuring tasks for details.
  2. タスクの説明を追加すると、タスクの作成理由を思い出すのに役立ちます。
  3. [このタスクを無効化] チェックボックスを使用して、タスクを実行するかどうかを制御します。
  4. Docker コンテナの実行コマンドを選択し、設定を完了します。設定の詳細については、以下をクリックしてください。

Docker イメージ 
Docker コンテナのインスタンスの作成に使用するイメージ
コンテナをデタッチ

デプロイメント プロジェクトの完了後、バックグランドでコンテナの実行を許可する

この上部の他のコンテナで使用されていないコンテナ名を指定します。

ポート マッピングの追加をクリックし、コンテナ内のポートをホスト上のポートに結び付けます。

サービスの開始を待つ

サービスを利用できるようになるまで Bamboo が待機する時間を指定できます。

Bamboo が確認する URL のパターンとタイムアウト期間を指定する必要があります。

デタッチ コンテナへのリンク
コンテナを、ジョブの先行タスクで開始したデタッチ コンテナへリンクさせることができます。
コンテナ環境変数

Allows you to specify parameters to pass to the container, for example JAVA_OPTS="-Xmx256m -Xms128m".

複数のパラメーターはスペースで区切ってください。スペースを使用したパラメーターには引用符を付ける必要があります。

コンテナ コマンド
Docker コンテナを実行するためのコマンド。

 

必要に応じて、詳細オプションを指定します。 

環境変数
(Optional)   Additional system environment variables that you want to pass to your build. Note that existing environment variables are automatically available to the executable. You can also include Bamboo global or build-specific variables (see Bamboo variables).
Multiple variables should be separated with spaces. Parameters with spaces must be quoted (e.g JAVA_OPTS="-Xms200m -Xmx700m").
作業サブディレクトリ
(オプション)  Bamboo が実行ファイルを実行する、ジョブのルート ディレクトリに相対的な代替サブディレクトリ。ルート ディレクトリには、ジョブの構成済みソース リポジトリから確認されたものがすべて含まれます。このフィールドを空白のまま残した場合、Bamboo はルート ディレクトリでビルド ファイルを検索します。このオプションは、サブディレクトリ内にビルド スクリプトがあり、実行可能ファイルをそのサブディレクトリ内から実行する必要がある場合に便利です。


変更を保存します。

Docker イメージを Docker レジストリにプッシュする

Docker を Docker イメージにプッシュします。これには、中心となる Docker ハブ レジストリまたはカスタム レジストリを使用できます。

Bam\boo から Docker リポジトリをレジストリにプッシュするには:

  1. Create a new Docker task for the relevant job. See Configuring tasks for details.
  2. タスクの説明を追加すると、タスクの作成理由を思い出すのに役立ちます。
  3. [このタスクを無効化] チェックボックスを使用して、タスクを実行するかどうかを制御します。
  4. Docker イメージを Docker リポジトリにプッシュするコマンドを選択し、設定を完了します。 設定の詳細については、以下をクリックしてください。

レジストリ
Docker Hub またはカスタム リポジトリのいずれかへのプッシュを選択します。
リポジトリ
For Docker Hub you must specify the repository name and optionally a tag, for example: namespace/repository:tag For a custom registry you must specify the registry address, repository name and optionally a tag, for example: registry.address:port/namespace/repository:tag
ユーザー名パスワードEメール
レジストリ アカウントの資格情報。エージェントの dockercfg ファイルを使用する場合は空白のまま残します。

 

必要に応じて、詳細オプションを指定します。 

環境変数
(Optional)  Additional system environment variables that you want to pass to your build. Note that existing environment variables are automatically available to the executable. You can also include Bamboo global or build-specific variables (see Bamboo variables).
Multiple variables should be separated with spaces. Parameters with spaces must be quoted (e.g JAVA_OPTS="-Xms200m -Xmx700m").
作業サブディレクトリ
(オプション)  Bamboo が実行ファイルを実行する、ジョブのルート ディレクトリに相対的な代替サブディレクトリ。ルート ディレクトリには、ジョブの構成済みソース リポジトリから確認されたものがすべて含まれます。このフィールドを空白のまま残した場合、Bamboo はルート ディレクトリでビルド ファイルを検索します。このオプションは、サブディレクトリ内にビルド スクリプトがあり、実行可能ファイルをそのサブディレクトリ内から実行する必要がある場合に便利です。


変更を保存します。

高度な認証

プッシュ タスクでは、認証目的でユーザー名、パスワード、および Eメールを定義できます。 

If the other tasks require authentication, or if you want to share credentials between all builds for certain agents, it's possible to create the docker configuration file on the agent itself, named ~/.dockercfg:

{
  "https://index.docker.io/v1/": {
    "auth": "xXxXxXxXxXx=",
    "email": "username@example.com"
  },
  "https://index.example.com": {
    "auth": "XxXxXxXxXxX=",
    "email": "username@example.com"
  }
}

プッシュタスクを使用する場合は、代わりに dockercfg を使用するため、認証フィールドを空白のまま残します。 

Docker command updates ~/.dockercfg file; if you have any configuration management tool in place updating this file (like puppet, chef or ansible), make sure it's not executing while you are running a docker build. 

トラブルシューティング

デバイスに空き容量が残っていない

Docker stores it's images in a local image installation directory. Over time this directory may grow to consume all of the available disk space. When this occurs you should remove unused images by running the docker rmi command.

ディスク容量に影響する次の Docker の問題によって詳細がわかる場合があります。

Docker コンテナ内で作成されたファイルでパーミッションが拒否された

Docker はルート ユーザーとしてコンテナ内で処理を実行します。つまり、マウント ボリューム上で作成されたファイルは,Docker コマンドを実行するユーザー (bamboo エージェント ユーザー) ではなく、ルート ユーザーによって所有されます。これにより、次のタスクでホスト上のこれらのファイルにアクセスする必要がある場合に問題が発生することがあります。

Docker は将来、コンテナとホスト ユーザーの間でのマッピングを許可する予定です。それまでの間、マウント ボリューム内のファイルの所有者をホスト ユーザーに変更することでこの問題を回避できます。

  • Docker run タスク構成で次の環境変数を設定することで、ホスト ユーザーの ID とグループ ID をコンテナに供給します。
    • HOST_UID=$UID
    • HOST_GID=$GID
  • マウント ボリューム内のファイルの所有者を変更するには、コンテナ内でスクリプトを実行します。 

    chown -R $HOST_UID:$HOST_GID /<path_to_mounted_volume>

Docker の実行中にパーミッションが拒否される

Docker コンテナを実行しようとすると、「permission denied」エラーが発生する場合があります。

2015/02/10 06:35:31 Post http:///var/run/docker.sock/build?rm=1&t=docker-toy-demo: dial unix /var/run/docker.sock: permission denied

解決策として、エージェントの Docker グループに Bamboo ユーザー エージェントを追加します。

有効な docker ファイルで実行エラーが発生する、または docker コンテナを起動できない

ビルド出力の例:

 Driver devicemapper failed to get image rootfs 511136ea3c5a64f264b78b5433614aec563103b4d4702f3ba7d4d2698e22c158: Error mounting '/dev/mapper/docker-202:16-17252355-511136ea3c5a64f264b78b5433614aec563103b4d4702f3ba7d4d2698e22c158' on '/mnt/docker/devicemapper/mnt/511136ea3c5a64f264b78b5433614aec563103b4d4702f3ba7d4d2698e22c158': invalid argument
simple    12-Feb-2015 12:12:14    Failing task since return code of [/usr/bin/docker build --no-cache=true --tag="docker.atlassian.io/dk:9.3" /home/bamboo/bamboo-agent-home/xml-data/build-dir/dkr-build-JOB1] was 1 while expected 0
error    12-Feb-2015 12:12:14    Error occurred while running Task 'Build docker image(5)' of type com.atlassian.bamboo.plugins.bamboo-docker-plugin:task.docker.cli.
error    12-Feb-2015 12:12:14    com.atlassian.bamboo.task.TaskException: Failed to execute task
error    12-Feb-2015 12:12:14        at com.atlassian.bamboo.plugins.docker.service.BuildService.execute(BuildService.java:53)
error    12-Feb-2015 12:12:14        at com.atlassian.bamboo.plugins.docker.tasks.cli.DockerCliTask.execute(DockerCliTask.java:60)
error    12-Feb-2015 12:12:14        at com.atlassian.bamboo.task.TaskExecutorImpl$3.call(TaskExecutorImpl.java:281)
error    12-Feb-2015 12:12:14        at com.atlassian.bamboo.task.TaskExecutorImpl$3.call(TaskExecutorImpl.java:278)
error    12-Feb-2015 12:12:14        at com.atlassian.bamboo.task.TaskExecutorImpl.executeTaskWithPrePostActions(TaskExecutorImpl.java:198)
error    12-Feb-2015 12:12:14        at com.atlassian.bamboo.task.TaskExecutorImpl.executeTasks(TaskExecutorImpl.java:278)
error    12-Feb-2015 12:12:14        at com.atlassian.bamboo.task.TaskExecutorImpl.execute(TaskExecutorImpl.java:105)
error    12-Feb-2015 12:12:14        at com.atlassian.bamboo.build.pipeline.tasks.ExecuteBuildTask.call(ExecuteBuildTask.java:75)
error    12-Feb-2015 12:12:14        at com.atlassian.bamboo.v2.build.agent.DefaultBuildAgent.build(DefaultBuildAgent.java:188)
error    12-Feb-2015 12:12:14        at com.atlassian.bamboo.v2.build.agent.BuildAgentControllerImpl.waitAndPerformBuild(BuildAgentControllerImpl.java:112)
error    12-Feb-2015 12:12:14        at com.atlassian.bamboo.v2.build.agent.DefaultBuildAgent$1.run(DefaultBuildAgent.java:110)
error    12-Feb-2015 12:12:14        at com.atlassian.bamboo.utils.BambooRunnables$1.run(BambooRunnables.java:49)
error    12-Feb-2015 12:12:14        at com.atlassian.bamboo.security.ImpersonationHelper.runWith(ImpersonationHelper.java:31)
error    12-Feb-2015 12:12:14        at com.atlassian.bamboo.security.ImpersonationHelper.runWithSystemAuthority(ImpersonationHelper.java:20)
error    12-Feb-2015 12:12:14        at com.atlassian.bamboo.security.ImpersonationHelper$1.run(ImpersonationHelper.java:52)
error    12-Feb-2015 12:12:14        at java.lang.Thread.run(Thread.java:745)
error    12-Feb-2015 12:12:14    Caused by: com.atlassian.bamboo.plugins.docker.client.DockerException: Error running Docker build command
error    12-Feb-2015 12:12:14        at com.atlassian.bamboo.plugins.docker.client.DockerCmd.build(DockerCmd.java:149)
error    12-Feb-2015 12:12:14        at com.atlassian.bamboo.plugins.docker.service.BuildService.execute(BuildService.java:40)
error    12-Feb-2015 12:12:14        ... 15 more
error    12-Feb-2015 12:12:14    Caused by: com.atlassian.utils.process.ProcessException: Error executing /usr/bin/docker build --no-cache=true --tag="docker.atlassian.io/dk:9.3" /home/bamboo/bamboo-agent-home/xml-data/build-dir/DDT-REP-JOB1
error    12-Feb-2015 12:12:14        at com.atlassian.bamboo.plugins.docker.process.DockerTaskProcessService.execute(DockerTaskProcessService.java:57)
error    12-Feb-2015 12:12:14        at com.atlassian.bamboo.plugins.docker.client.DockerCmd.build(DockerCmd.java:145)
error    12-Feb-2015 12:12:14        ... 16 more

 

If the agent consistently fails executing docker run commands, either when building an image or running an instance there is a risk that you've run into https://github.com/docker/docker/issues/4036 To help diagnose this you can SSH to the agent and look at the kernel messages by running:

dmesg

この問題を示すメッセージは数種類あります。例:

[83471099.881879] JBD2: no valid journal superblock found
[83471099.881883] EXT4-fs (dm-2): error loading journal
[88401612.723018] EXT4-fs (dm-1): warning: mounting fs with errors, running e2fsck is recommended
[88401612.724764] EXT4-fs (dm-1): mounted filesystem with ordered data mode. Opts: discard
[88401612.744549] EXT4-fs error (device dm-1): ext4_lookup:1448: inode #2: comm docker: deleted inode referenced: 131073

 

デバイス マッパーが破損するという大きなリスクがあります。つまり、Docker を停止し、devicemapper が使用するファイルを削除してから、Docker を再起動する必要があります。エラスティック エージェントで実行している場合は、エージェントを終了してから新しく起動するオプションも選択できます。

Docker を停止してファイルを削除するには、以下を実行します。

sudo -i
#stop the docker daemon
service docker stop
#remove the broken devicemapper files
rm -rf /var/lib/docker 
service docker start

devicemapper ファイルの位置は上記の例とは異なる場合があります。正確なパスを探すには、以下を実行します。

docker info

Stock images fail to mount when EXT4 is utilized as a filesystem

Example output:

[ 1918.530083] EXT4-fs warning (device dm-3): dx_probe:726: dx entry: limit != root limit
[ 1918.530086] EXT4-fs warning (device dm-3): dx_probe:804: Corrupt dir inode 132551, running e2fsck is recommended.
[ 2163.888683] init: docker main process (1156) killed by KILL signal
[ 2209.211501] audit: type=1400 audit(1427777910.502:14): apparmor="STATUS" operation="profile_replace" profile="unconfined" name="docker-default" pid=7152 comm="apparmor_parser"
[ 2273.905293] device-mapper: thin: Creation of new snapshot 0 of device 46 failed.
[ 2273.905293] device-mapper: thin: Creation of new snapshot 1 of device 46 failed.
...

If you install the linux-image-extra package before Docker, it will enable AUFS support. This is mentioned on the Ubuntu install docs, but it is noted below the 13.04/13.10 instructions.

If you already have Docker installed and if facing the issue above, please find bellow a quick uninstall/reinstall.

Note the steps bellow will delete all images and containers

$ sudo -i
# service docker stop
# apt-get remove lxc-docker
# apt-get autoremove
# rm -rf /var/lib/docker
# apt-get update
# apt-get install linux-image-extra-`uname -r`
# apt-get install lxc-docker
# docker info


  • ラベルなし