[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.
The Docker task supports the following Docker actions:
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.
Builds a Docker image based on the specified Dockerfile. The Dockerfile may be provided as an existing file in the task's working directory or defined in the task configuration.
The image is stored in Docker's local image installation directory and can be used by subsequent Docker tasks in the job. You can optionally save the image to a file in the working directory which can then be packaged as a build artifact.
To build a Docker image in Bamboo:
Choose the Build a Docker image command and complete the settings. Click below to see more information about the settings:
Starts a Docker container based on the specified image.
The task's working directory is mounted and also used as the Docker container's working directory.
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.
To run a Docker container in Bamboo:
Choose the Run a Docker container command and complete the settings. Click below to see more information about the settings:
Pushes a Docker image to a Docker registry. This may be the central Docker Hub registry or a custom registry.
To push a Docker repository from Bamboo to a registry:
Choose the Push a Docker image to a Docker registry command and complete the settings. Click below to see more information about the settings:
The push task allows you to define username, password and email for authentication purposes.
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" } }
When using the push task, leave authentication fields empty in order to use dockercfg instead.
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.
The following Docker issues affecting disk space may provide further information:
Docker runs processes inside containers as the root user. This means files created on mounted volumes are owned by the root user and not by the user running the Docker command (the bamboo agent user). This may cause an issue if a subsequent task requires access to those files on the host.
Docker plans to allow mapping between container and host users in the future. Until then, you can work around this issue by changing the owner of the files in the mounted volume to the host user:
HOST_UID=$UID
HOST_GID=$GID
Run a script inside the container to change the owner of the files in the mounted volume:
chown -R $HOST_UID:$HOST_GID /<path_to_mounted_volume>
When attempting to run a Docker container you may see a 'permission denied' issue:
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
The solution is to add the Bamboo user agent to the Docker group on the agent.
Example build output:
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
There are several possible messages that indicate this problem. Some of those are listed here:
[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
There is a big risk that the device mapper is corrupt. This means that you need to stop Docker and remove the files used by devicemapper, then restart Docker. If running on an elastic agent, terminating the agent and starting a new one is also a viable option.
To stop Docker and remove the files, run the following:
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
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