ko — Build and Deploy Go Container Images Without Dockerfiles
ko builds Go applications into container images without a Dockerfile or Docker daemon, producing minimal images and deploying them directly to Kubernetes with a single command.
What it is
ko is a build tool for Go applications that creates container images without requiring a Dockerfile or a running Docker daemon. It compiles your Go binary and layers it onto a minimal distroless base image, producing small, secure containers. ko can also deploy directly to Kubernetes by replacing image references in YAML manifests with the built image.
ko is designed for Go developers who want fast, simple container builds without writing or maintaining Dockerfiles.
How it saves time or tokens
Traditional container builds for Go apps require writing a Dockerfile, building a Docker image, pushing to a registry, and updating Kubernetes manifests. ko collapses all of that into a single command. ko build ./cmd/myapp compiles, builds the image, and pushes it. ko apply -f deployment.yaml goes further by building the image and applying the manifest to your cluster in one step. Build times are faster because ko skips the Docker layer cache dance and builds only the Go binary.
How to use
- Install ko:
go install github.com/ko-build/ko@latest
- Set your container registry:
export KO_DOCKER_REPO=ghcr.io/myorg
- Build and push an image:
ko build ./cmd/myapp
Or build and deploy to Kubernetes:
ko apply -f deploy/
ko replaces ko://./cmd/myapp references in your YAML with the actual image digest.
Example
A Kubernetes deployment manifest using ko image references:
apiVersion: apps/v1
kind: Deployment
metadata:
name: myapp
spec:
replicas: 2
selector:
matchLabels:
app: myapp
template:
metadata:
labels:
app: myapp
spec:
containers:
- name: myapp
image: ko://./cmd/myapp
ports:
- containerPort: 8080
Running ko apply -f deploy.yaml builds the Go binary, creates a container image, pushes it to your registry, replaces ko://./cmd/myapp with the digest reference, and applies the manifest to your cluster.
Related on TokRepo
- DevOps tools — Browse container and deployment tools
- Automation tools — Explore build automation tools
Common pitfalls
- Forgetting to set
KO_DOCKER_REPO. Without this environment variable, ko does not know which registry to push images to and will fail. - Expecting ko to work with non-Go applications. ko is specifically designed for Go. For other languages, you still need Dockerfiles or language-specific build tools.
- Not using the
.ko.yamlconfig file for custom base images. The default distroless base is minimal but may lack tools you need for debugging. Configure a custom base image in.ko.yamlif needed. - Starting with an overly complex configuration instead of defaults. Begin with the minimal setup, verify it works, then customize incrementally. This approach catches configuration errors early and keeps troubleshooting straightforward.
Frequently Asked Questions
ko uses Google's distroless base image by default, which contains only the Go binary and CA certificates. This produces images under 20MB. You can override the base image in a .ko.yaml configuration file.
Yes. ko supports building multi-platform images (linux/amd64, linux/arm64) with the --platform flag. It cross-compiles the Go binary for each target platform and creates a manifest list.
Yes. Use ko build --local to build the image and load it into your local Docker daemon without pushing. This is useful for local development and testing.
ko is typically faster because it skips Docker layer caching and builds only the Go binary. A ko build that takes 5 seconds might take 30+ seconds with Docker. The difference is more pronounced in CI environments where Docker layer caches are cold.
Yes. ko uses the standard Go toolchain and respects go.mod, go.sum, and all Go build flags. Any Go project that builds with go build will work with ko.
Citations (3)
- ko GitHub— ko builds Go container images without Dockerfile
- Google Distroless— Distroless base images by Google
- ko Documentation— ko documentation and configuration
Related on TokRepo
Discussion
Related Assets
Conda — Cross-Platform Package and Environment Manager
Install, update, and manage packages and isolated environments for Python, R, C/C++, and hundreds of other languages from a single tool.
Sphinx — Python Documentation Generator
Generate professional documentation from reStructuredText and Markdown with cross-references, API autodoc, and multiple output formats.
Neutralinojs — Lightweight Cross-Platform Desktop Apps
Build desktop applications with HTML, CSS, and JavaScript using a tiny native runtime instead of bundling Chromium.