TeamCity On-Premises 2020.2 Help

Docker Wrapper

The Docker Wrapper extension allows running a build step inside the specified Docker image.

The extension is available for the following build runners:

Each of the supported runners has the dedicated Docker settings section.

Docker Settings

In the Docker Settings section of the build step settings, you can specify a Docker image which will be used to run the build step. Once the image is specified, the following options become available.



Run step within Docker container

Specify a Docker image name as stated in Docker Hub. TeamCity will start a container from the specified image and will try to run this build step within this container.

For example, ruby:2.4 will run the step within the Ruby container, version 2.4.

Docker image platform

Select <Any> (default), Linux, or Windows.

Pull image explicitly

If enabled, the image will be pulled from the Hub repository via docker pull <imageName> before the docker run command is launched.

Additional docker run arguments

Allows specifying additional options for the docker run command. The default argument is --rm, but you can provide more, for instance, add an additional volume mapping.

How It Works

Technically, the command of the build runner is wrapped in a shell script, and this script is executed inside a Docker container with the docker run command. All the details about the started process, text of the script, and so on, are written into the build log (the Verbose mode enables viewing them).

The build checkout directory and most build agent directories are mapped inside the Docker process.

At the end of the build step with the Docker wrapper, a build agent runs the chown command to restore access of the buildAgent user to the checkout directory. This mitigates a possible problem when the files from a Docker container are created with the root ownership and cannot be removed by the build agent later.

If the process environment contains the TEAMCITY_DOCKER_NETWORK environment variable set by the previous Docker Compose build step, this network is passed to the started docker run command with the --network switch.

Environment Variables Handling

TeamCity passes environment variables from the build configuration into the Docker process, but it does not pass environment variables from the build agent, as they may not be relevant to the Docker container environment. The list of the passed environment variables can be seen in the Verbose mode in the build log.

Setting Image Entrypoint

If you want to run a container with a specific ENTRYPOINT, follow these steps:

  1. Create a Command Line build step.

  2. Set the Run mode to Executable with parameters.

  3. In the Command executable field, specify the full path to the ENTRYPOINT in the target Docker container.

  4. In Docker Settings, specify the name of the Docker container.

TeamCity will start the specified Docker image with the defined ENTRYPOINT.

Last modified: 13 May 2021