Bamboo での Docker タスクの設定

お困りですか?

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

コミュニティに質問

 

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

If you're using a Windows Bamboo server, you can't run Docker commands directly from the Windows command line.

To use the Docker task with a Windows Bamboo server, run Docker Machine.

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

Docker タスクを設定する前に、エージェントで Docker の機能を定義してください。

For examples of how to use Docker in Bamboo, see the Bamboo, Docker, and building web apps blog post.

Note that Bamboo requires Docker 1.7.1 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. 関連ジョブ用に新しい Docker タスクを作成します。詳細については、タスクの構成を参照してください。
  2. タスクの説明を追加すると、タスクの作成理由を思い出すのに役立ちます。
  3. [このタスクを無効化] チェックボックスを使用して、タスクを実行するかどうかを制御します。
  4. Docker イメージのビルドコマンドを選択し、設定を完了します。設定の詳細については、以下をクリックしてください。

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.

Select Do not use cache... to ensure that the new image will include changes since the last build. Note that this may incur a performance penalty.

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

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 はルート ディレクトリでビルド ファイルを検索します。このオプションは、サブディレクトリ内にビルド スクリプトがあり、実行可能ファイルをそのサブディレクトリ内から実行する必要がある場合に便利です。

 

Save your changes!

Docker コンテナを実行する

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

By default, the task's working directory is mounted and used as the Docker container's working directory, but you can specify your own settings.

By default, the container is removed on completion of the task, but you can choose Detach container to have the container continue to run after a deployment project completes. Containers can be linked to detached containers started by preceding tasks in a job by selecting the 'Link to detached containers' option.

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. 関連ジョブ用に新しい Docker タスクを作成します。詳細については、タスクの構成を参照してください。
  2. タスクの説明を追加すると、タスクの作成理由を思い出すのに役立ちます。
  3. [このタスクを無効化] チェックボックスを使用して、タスクを実行するかどうかを制御します。
  4. Docker コンテナの実行コマンドを選択し、設定を完了します。設定の詳細については、以下をクリックしてください。

Docker コンテナの実行...
Docker イメージ 

 

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

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

Specify a Container name that isn't used by other containers in this job.

Click Add port mapping to specify mappings that bind ports inside the container to ports on the host.

サービスの開始を待つ

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

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

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

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

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

コンテナ コマンド
Docker コンテナを実行するためのコマンド。
Container working directory
The working directory for the container.
Additional arguments
Additional Docker run options.
ボリューム

You can mount additional host directories as data volumes inside the container.

 

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

環境変数
(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").
作業サブディレクトリ
(Optional)   An alternative subdirectory, relative to the job's root directory, where Bamboo will run the executable. The root directory contains everything checked out from the job's configured source repository. If you leave this field blank, Bamboo will look for build files in the root directory. This option is useful if your task has a build script in a subdirectory and the executable needs to be run from within that subdirectory.

 

Save your changes!

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

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

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

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

Docker イメージを Docker レジストリにプッシュする...
レジストリ
Docker Hub またはカスタム リポジトリのいずれかへのプッシュを選択します。
リポジトリ
For Docker Hub you must specify the repository name and optionally a tag, for example: namespace/repository:tagFor a custom registry you must specify the registry address, repository name and optionally a tag, for example: registry.address:port/namespace/repository:tag
UsernamePassword, Email
レジストリ アカウントの資格情報。エージェントの 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 はルート ディレクトリでビルド ファイルを検索します。このオプションは、サブディレクトリ内にビルド スクリプトがあり、実行可能ファイルをそのサブディレクトリ内から実行する必要がある場合に便利です。

 

Save your changes!

高度な認証

プッシュ タスクでは、認証目的でユーザー名、パスワード、および 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

The location of the devicemapper files may differ from the example above. Run the following to find the exact path:

docker info
最終更新日 2016 年 5 月 24 日

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

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