[Bamboo Cloud docs]
[Bamboo Knowledge Base]
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.
指定した Dockerfile に基づいて Docker イメージをビルドします。Dockerfile は、タスクの作業ディレクトリ内の既存のファイルとして提供されてあり、タスク設定で定義される場合があります。
イメージは Docker のローカル イメージ インストール ディレクトリに保存され、ジョブ内においてその後の Docker タスクで使用できます。オプションとして、イメージを作業ディレクトリのファイルに保存した後、ビルド アーティファクトとしてパッケージ化できます。
Bamboo で Docker イメージをビルドするには
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 コンテナを実行するには:
Docker コンテナの実行コマンドを選択し、設定を完了します。設定の詳細については、以下をクリックしてください。
Docker を Docker イメージにプッシュします。これには、中心となる Docker ハブ レジストリまたはカスタム レジストリを使用できます。
Bam\boo から Docker リポジトリをレジストリにプッシュするには:
Docker イメージを Docker リポジトリにプッシュするコマンドを選択し、設定を完了します。 設定の詳細については、以下をクリックしてください。
プッシュ タスクでは、認証目的でユーザー名、パスワード、および 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 コマンドを実行するユーザー (bamboo エージェント ユーザー) ではなく、ルート ユーザーによって所有されます。これにより、次のタスクでホスト上のこれらのファイルにアクセスする必要がある場合に問題が発生することがあります。
Docker は将来、コンテナとホスト ユーザーの間でのマッピングを許可する予定です。それまでの間、マウント ボリューム内のファイルの所有者をホスト ユーザーに変更することでこの問題を回避できます。
HOST_UID=$UID
HOST_GID=$GID
マウント ボリューム内のファイルの所有者を変更するには、コンテナ内でスクリプトを実行します。
chown -R $HOST_UID:$HOST_GID /<path_to_mounted_volume>
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 ユーザー エージェントを追加します。
ビルド出力の例:
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
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