Running a Docker container in Bamboo

On this page

Still need help?

The Atlassian Community is here for you.

Ask the community

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 select 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:

  1. In the job configuration screen, select Add task.
  2. Search for the Docker tasks type and select it.
  3. (optional) For future reference, add a Task description.
  4. (optional) Use the Disable this task checkbox to control whether your task gets run.
  5. (optional) Use the Add condition to task checkbox to make task run only when a certain condition is met. 
    You can find conditions on Atlassian Marketplace or implement your own.  
  6. Select the Run a Docker container command and complete the settings. See more information about the settings below:

    Run a Docker container...
    Docker image 

    Run a Docker image option in Docker task configuration


    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.

    Select 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 JAVA_OPTS="-Xmx256m -Xms128m".

    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.


    If required, specify advanced options: 

    Environment variables
    (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").
    Working subdirectory
    (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!

Last modified on Jun 2, 2021

Was this helpful?

Yes
No
Provide feedback about this article
Powered by Confluence and Scroll Viewport.