Running a Docker container in Bamboo
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.
Before you begin
- Make sure you have Docker installed. We advise to use the most recent version.
Define a Docker capability in Bamboo. See Defining a new Docker capability
- If you're using Bamboo on Windows, you can't run Docker commands directly from the Windows command line. To use Docker tasks with Bamboo Windows, run Docker Machine.
To run a Docker container in Bamboo:
- In you job configuration screen, click Add task.
- Search for the Docker tasks type and select it.
- (optional) For future reference, add a Task description.
- (optional) Use the Disable this task checkbox to control whether your task gets run.
From the Repository drop-down list, choose Run a Docker container.
Complete the task settings:Run a Docker container...
Docker image The image you want to use to instantiate the Docker container Detach container
Allows you to run the container in the background, after a deployment project completes
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.
Wait for service to start
Allows you to specify how long Bamboo should wait for the service to become available.
You need to specify a pattern for the URL that Bamboo should check, and a timeout period.
Link to detached containers Allows you to link containers to detached containers started by preceding tasks in a job. Container environment variables
Allows you to specify parameters to pass to the container, for example
Separate multiple parameters with spaces. Parameters with spaces must be quoted.
Container command The command to run in the Docker container. Container working directory The working directory for the container. Additional arguments
Additional Docker run options.
Argument strings that have values which contain spaces require the entire argument string be contained within quotes, that is, the parameter marker, the parameter, the equals sign, and the value containing spaces. For example:
"--health-cmd=mysqladmin ping || exit 1"
Volumes You can mount additional host directories as data volumes inside the container. Advanced options (optional) Environment variables 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").
Working sub directory 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.