This example demonstrates how to build a Docker image within a Tekton Task using a Docker-in-Docker (DinD) sidecar.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/tektoncd/pipeline/llms.txt
Use this file to discover all available pages before exploring further.
Example
How It Works
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.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.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 TCPDOCKER_TLS_VERIFY=1- Enable TLS verificationDOCKER_CERT_PATH=/certs/client- Use shared certificates
Security Considerations
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:- Sidecar sets
DOCKER_TLS_CERTDIR=/certsto generate certs - Both containers mount the same
dind-certsvolume - Client reads certificates from
/certs/client - 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
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
- See git clone and build for a complete CI workflow
- Learn about multi-stage pipelines