Docker Build

Docker Build

Certified

Build and optionally push a Docker image

Builds an image from inline Dockerfile content or a path using the Docker daemon available to the task runner. Pulls the base image by default, tags are required, and pushing is optional with registry credentials; caller inherits daemon permissions.

yaml
type: io.kestra.plugin.docker.Build

Build and push a Docker image to a registry

yaml
id: docker_build
namespace: company.team

tasks:
  - id: build
    type: io.kestra.plugin.docker.Build
    push: true
    dockerfile: |
      FROM ubuntu
      ARG APT_PACKAGES=""
      RUN apt-get update && apt-get install -y --no-install-recommends ${APT_PACKAGES};
    platforms:
      - linux/amd64
    tags:
      - private-registry.io/unit-test:latest
    buildArgs:
      APT_PACKAGES: curl
    labels:
      unit-test: "true"
    credentials:
      registry: <registry.url.com>
      username: "{{ secret('DOCKERHUB_USERNAME') }}"
      password: "{{ secret('DOCKERHUB_PASSWORD') }}"

Build and push a docker image to DockerHub

yaml
id: build_dockerhub_image
namespace: company.team

tasks:
  - id: build
    type: io.kestra.plugin.docker.Build
    dockerfile: |
      FROM python:3.10
      RUN pip install --upgrade pip
      RUN pip install --no-cache-dir kestra requests "polars[all]"
    tags:
      - kestra/polars:latest
    push: true
    credentials:
      registry: https://index.docker.io/v1/
      username: "{{ secret('DOCKERHUB_USERNAME') }}"
      password: "{{ secret('DOCKERHUB_PASSWORD') }}"

Build a Docker image and push it to GitHub Container Registry (ghcr.io)

yaml
id: build_github_container_image
namespace: company.team

tasks:
  - id: build
    type: io.kestra.plugin.docker.Build
    dockerfile: |
      FROM python:3.10
      RUN pip install --upgrade pip
      RUN pip install --no-cache-dir kestra requests "polars[all]"
    tags:
      - ghcr.io/kestra-io/polars:latest
    push: true
    credentials:
      username: kestra-io
      password: "{{ secret('GITHUB_ACCESS_TOKEN') }}"

Build a Docker image and use it with Python script using a Docker Task Runner

yaml
id: build_task_runner_image
namespace: company.team

tasks:
  - id: build
    type: io.kestra.plugin.docker.Build
    tags:
      - my-py-data-app
    dockerfile: |
      FROM python:3.12-slim
      WORKDIR /app
      RUN pip install --no-cache-dir pandas
      COPY . /app

  - id: python
    type: io.kestra.plugin.scripts.python.Commands
    containerImage: "{{ outputs.build.imageId }}"
    taskRunner:
      type: io.kestra.plugin.scripts.runner.docker.Docker
      pullPolicy: NEVER
    namespaceFiles:
      enabled: true
    commands:
      - python main.py
Properties
SubTypestring

Image tags

Include the registry host for custom registries. For insecure HTTP registries, configure /etc/docker/daemon.json as shown in the linked gist and restart Docker (systemctl daemon-reload && systemctl restart docker).

Build arguments

Optional key/value map rendered before invoking the build.

Docker configuration file

Docker configuration file that can set access credentials to private container registries. Usually located in ~/.docker/config.json.

Credentials for a private container registry

Definitions
authstring

The registry authentication.

The auth field is a base64-encoded authentication string of username: password or a token.

identityTokenstring

The identity token.

passwordstring

The registry password.

registrystring

The registry URL.

If not defined, the registry will be extracted from the image name.

registryTokenstring

The registry token.

usernamestring

The registry username.

Dockerfile content or path

Inline Dockerfile text, a relative path in the working directory, or a Kestra URI; inline content is stored as a temp file before build.

The URI of your Docker host e.g. localhost

The files to create on the working. It can be a map or a JSON object.

Each file can be defined:

  • Inline with its content
  • As a URI, supported schemes are kestra for internal storage files, file for host local files, and nsfile for namespace files.

Image labels

Key/value labels to apply to the built image.

Inject namespace files.

Inject namespace files to this task. When enabled, it will, by default, load all namespace files into the working directory. However, you can use the include or exclude properties to limit which namespace files will be injected.

Definitions
enabledbooleanstring
Defaulttrue

Whether to enable namespace files to be loaded into the working directory. If explicitly set to true in a task, it will load all Namespace Files into the task's working directory. Note that this property is by default set to true so that you can specify only the include and exclude properties to filter the files to load without having to explicitly set enabled to true.

excludearray
SubTypestring

A list of filters to exclude matching glob patterns. This allows you to exclude a subset of the Namespace Files from being downloaded at runtime. You can combine this property together with include to only inject a subset of files that you need into the task's working directory.

folderPerNamespacebooleanstring
Defaultfalse

Whether to mount file into the root of the working directory, or create a folder per namespace

ifExistsstring
DefaultOVERWRITE
Possible Values
OVERWRITEFAILWARNIGNORE

Comportment of the task if a file already exist in the working directory.

includearray
SubTypestring

A list of filters to include only matching glob patterns. This allows you to only load a subset of the Namespace Files into the working directory.

namespacesarray
SubTypestring
Default["{{flow.namespace}}"]

A list of namespaces in which searching files. The files are loaded in the namespace order, and only the latest version of a file is kept. Meaning if a file is present in the first and second namespace, only the file present on the second namespace will be loaded.

SubTypestring

Target platforms for the image

Each entry is passed to buildx as --platform; leave empty to use the daemon default.

Reference (ref) of the pluginDefaults to apply to this task.

Defaulttrue

Pull the base image first

Defaults to true so the build uses the latest base image; set false to rely on cached layers.

Defaultfalse

Push the image to a registry

Defaults to false; when true, tags are pushed using the provided credentials.

Target build stage

Name of the build stage to stop at in a multi-stage Dockerfile; equivalent to --target.

Built image ID

Unitbytes

Total bytes pushed to the container registry