Skip to main content
This example demonstrates how to build a Docker image within a Tekton Task using a Docker-in-Docker (DinD) sidecar.

Example

How It Works

1

Sidecar Starts Docker Daemon

The sidecar container runs a Docker daemon with TLS enabled. It generates certificates and writes them to a shared volume at /certs/client.
2

Startup Probes Wait for Daemon

The startupProbe waits for the certificates to be generated (up to 30 seconds). The readinessProbe verifies the daemon is ready to accept commands.
3

Client Connects to Daemon

The client step configures the Docker CLI to connect to the sidecar daemon using environment variables:
  • DOCKER_HOST=tcp://localhost:2376 - Connect via TCP
  • DOCKER_TLS_VERIFY=1 - Enable TLS verification
  • DOCKER_CERT_PATH=/certs/client - Use shared certificates
4

Build and Run Docker Image

The client step:
  1. Runs a simple busybox container to verify connectivity
  2. Creates a Dockerfile
  3. Builds an image tagged as hello
  4. Runs the newly built image

Security Considerations

The Docker daemon sidecar requires privileged: true to function. This grants significant permissions to the container. Only use this in trusted environments.

Docker Daemon Configuration

The daemon is configured with specific arguments:
  • --storage-driver=vfs - Uses VFS storage driver (slower but more compatible)
  • --userland-proxy=false - Disables userland proxy
  • --debug - Enables debug logging

TLS Certificate Sharing

The pattern for sharing TLS certificates:
  1. Sidecar sets DOCKER_TLS_CERTDIR=/certs to generate certs
  2. Both containers mount the same dind-certs volume
  3. Client reads certificates from /certs/client
  4. Docker CLI automatically uses these certificates

Expected Output

Alternative Approaches

For production use, consider:
  • Kaniko: Builds images without requiring privileged mode
  • Buildah: Daemonless container builds
  • BuildKit: Modern Docker build backend with better caching
These alternatives are more secure and work better in restricted environments.

Key Concepts

  • Sidecars: Containers that run alongside task steps to provide services
  • Docker-in-Docker (DinD): Running Docker daemon inside a container
  • Startup Probes: Wait for slow-starting containers to be ready
  • Shared Volumes: Pass data between steps and sidecars
  • TLS Security: Secure communication between Docker client and daemon
  • Privileged Containers: Required for DinD but should be used carefully

Next Steps