ConfigsApr 16, 2026·3 min read

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.

TL;DR
ko builds Go apps into minimal container images without Dockerfile or Docker daemon and deploys directly to Kubernetes.
§01

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.

§02

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.

§03

How to use

  1. Install ko:
go install github.com/ko-build/ko@latest
  1. Set your container registry:
export KO_DOCKER_REPO=ghcr.io/myorg
  1. 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.

§04

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.

§05

Related on TokRepo

§06

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.yaml config 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.yaml if 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

What base image does ko use?+

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.

Does ko support multi-platform builds?+

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.

Can ko build images without pushing to a registry?+

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.

How fast is ko compared to Docker builds?+

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.

Does ko work with Go modules?+

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)

Discussion

Sign in to join the discussion.
No comments yet. Be the first to share your thoughts.

Related Assets