Background step
Run dependent services, including Docker in Docker, for the lifetime of a Continuous Delivery step group or stage
Background steps run dependent services needed for the entire lifetime of a Continuous Delivery step group or stage. For example, you can set up your stage to run multiple background services that implement a local, multi-service app.
What you will learn from this topic
How to add a Background step for Docker in Docker in a containerized step group
How to name the step and call its service from a later step
How to set the image, entry point, and command
How to read the DinD setup in the step log and confirm the Background step started
Before you begin
Review the following setup before you add a Background step:
Containerized step group: Add the Background step inside a containerized step group. Go to Containerize step groups to run Continuous Delivery steps on your Kubernetes cluster.
Cluster and connector access: You need a Kubernetes cluster and a Harness Kubernetes connector the step group can use. Go to Containerize step groups to review infrastructure requirements.
Pipeline edit access: View and Create/Edit permissions on Pipelines so you can add or edit steps. Go to RBAC in Harness to configure roles.
Docker in Docker (DinD)
Some steps in a containerized step group might require Docker in Docker (DinD). For example, some deployment types might use DinD because of the requirements of their platforms.
If any step in a containerized step group requires DinD, you can add a Background step that performs the Docker in Docker (DinD) setup.

The Background step creates the DinD environment. In this environment, each subsequent step group step runs inside the Kubernetes pod as containers.
Background step settings
The Background step has the following settings.
Name and Id
When you name the step, Harness automatically adds an Id based on the name.
You can use the Background step Id to call services started by Background steps in later steps, such as commands in Run steps. For example, a cURL command could call STEPGROUPID_BACKGROUNDSTEPID:5000 where it might otherwise call localhost:5000.

You must include the step group Id, such as curl STEP_GROUP_ID_BACKGROUND_STEP_ID:5000, even if both steps are in the same step group.
Container registry
Container Registry is the Harness container registry connector that connects to the container registry hosting the image to use for this step.
Image
This is the container image to use for the background service.
For example, docker:dind.
The image name should include the tag, or it defaults to the latest tag if unspecified. You can use any Docker image from any Docker registry, including Docker images from private registries. Different container registries require different name formats:
Docker Registry: Enter the name of the artifact you want to use, such as
library/tomcat. Wildcards are not supported. The fully qualified name (FQN) is required for images in private container registries.ECR: Enter the FQN of the artifact you want to use. Images in repos must reference a path, for example:
<aws-account-id>.dkr.ecr.us-east-1.amazonaws.com/todolist:0.2.GCR: Enter the FQN of the artifact you want to use. Images in repos must reference a path starting with the project Id that the artifact is in, for example:
us.gcr.io/<project-id>/quickstart-image:latest.
Entry point
Supply a list of arguments in exec format. Enter each argument separately.

Entry Point arguments override the image ENTRYPOINT and any commands in the Command field.
Shell and command
For Shell, select the shell script type for the arguments and commands defined in Entry Point and Command.
In Command, enter POSIX shell script commands to execute inside the container.
For example, a command that checks the Java version installed on the system and verifies if it is equal to 17:
The following notes apply to commands in this step:
You can use
docker-compose upto start multiple services in one Background step.You can run PowerShell commands on Windows VMs running in AWS build farms.
You can run PowerShell Core commands in pods or containers that have pwsh installed.
Privileged
Enable this option to run the container with escalated privileges. This is equivalent to running a container with the Docker --privileged flag.
Report paths
Specify the file paths or directories within the container where various reports or log files generated by applications or processes running inside the container are stored.
Environment variables
You can inject environment variables into a container and use them in the Command script. You must enter a Name and Value for each variable.
You can reference environment variables in the Command script by their name. For example, a Bash script would use $var_name or ${var_name}, and a Windows PowerShell script would use $Env:varName.
Image pull policy
Select an option to set the pull policy for the image:
Always: The kubelet queries the container image registry to resolve the name to an image digest every time the kubelet launches a container. If the kubelet encounters an exact digest cached locally, it uses its cached image; otherwise, the kubelet downloads (pulls) the image with the resolved digest, and uses that image to launch the container.
If Not Present: The image is pulled only if it is not already present locally.
Never: The image is assumed to exist locally. No attempt is made to pull the image.
Set container resources
Maximum resource limits for containers that run this Background step. Go to Resource units in Kubernetes to review Kubernetes resource units.
DinD Background step example
When you run a pipeline that uses a containerized step group and Background step, you can see the DinD set up in the step log in the pipeline execution.
Select the step to see its log and how the DinD is set up. The general sequence is:
The log shows certificate requests being self-signed for the Docker in Docker (DinD) server and client.
The DinD environment is starting up.
It indicates that containerd is not running and starts the managed containerd process.
Containerd starts with information about the revision and version.
Various plugins are loaded, such as snapshotter, content, metadata, differ, event, GC scheduler, lease manager, NRI (disabled), runtime, sandbox, streaming, and services.
The log ends without further actions or errors.
Advanced settings
In Advanced, you can use the following options:
Troubleshooting
Next steps
Containerize step groups: Enable container-based execution for Continuous Delivery steps.
Run step: Run scripts in a container image inside the same step group.
Conditional execution settings: Control when the Background step runs.
Failure strategy settings: Configure what happens if the step fails.
Last updated
Was this helpful?