The Problem

Developers that need a programmable, extensible container engine must start from Docker’s monolithic source or re‑implement low‑level plumbing. Without a stable, language‑native API surface, integrating custom runtimes, registries, or orchestration components forces teams to copy‑paste large code blocks, increasing maintenance burden and risk of divergence from upstream security fixes.

What This Does

The repository ships the Moby API package – the canonical Go definitions for Docker Engine JSON endpoints. Key files include:

api/go.mod & api/go.sum – define the module github.com/moby/moby/api and its dependencies. api/pkg/... – concrete types such as container/config.go, network/network.go, and image/image.go that map directly to Engine request/response payloads. api/swagger.yaml and api/swagger-gen.yaml – machine‑readable OpenAPI specs generated from the same Go structs, enabling client code generation in any language.

The root also contains a Dockerfile (and platform‑specific variants) and a Makefile that drive container‑based builds and unit‑test execution via GitHub Actions (.github/workflows/.yml). The client/ package (not listed but present in the upstream tree) consumes these types to provide a fully‑typed Go client.

How To Use It

StepActionEvidence
Install dependenciesgo mod download inside api/api/go.mod lists required modules
Run unit testsmake test (or go test ./... in api/)Makefile defines a test target; 16 test files exist under api/
Generate client codego run ./cmd/genclient (if present) or use the OpenAPI spec: swagger-codegen generate -i api/swagger.yaml -l go -o ./clientapi/swagger.yaml provides the spec; api/scripts/generate-swagger-api.sh shows the generation pipeline
Build a container imagedocker build -f Dockerfile .Root Dockerfile builds the engine from source
Consume the APIImport github.com/moby/moby/api/types/... in your Go project and construct request structs, e.g.:<br>cfg := types.ContainerConfig{Image: "alpine", Cmd: []string{"sh"}}Types are defined in api/types/container/config.go and exercised by api/types/container/configtest.go

If the repository is intended solely as a library, the typical entry point is the Go module in api/. No additional runtime scripts are provided.

Real‑World Use

A CI system that needs to spin up transient containers can embed the Moby API as a library:

import ( "github.com/moby/moby/api/types" "github.com/moby/moby/client" )

func main() { cli, := client.NewClientWithOpts(client.FromEnv) cfg := types.ContainerConfig{ Image: "golang:1.22", Cmd: []string{"go", "test", "./..."}, } resp, _ := cli.ContainerCreate(context.Background(), &cfg, nil, nil, nil, "") cli.ContainerStart(context.Background(), resp.ID, types.ContainerStartOptions{}) }

The code compiles against the api types, guaranteeing payload compatibility with any Docker‑compatible engine.

Code Health & Issues

Low – Missing root go.mod – The top‑level module is absent, requiring consumers to cd api before go build. This adds friction for projects that expect a single module. Low – Limited build documentation – No README section describes the make targets or Docker build flags; developers must infer steps from the Makefile and CI workflows. Low – No versioned release tags in this fork – The upstream moby/moby tags are not mirrored, making dependency pinning harder. Low – Test coverage – 16 test files exist, but coverage metrics are not published; potential gaps in edge‑case handling (e.g., Windows‑specific structs) remain unverified. Low – No secret scanning – No evidence of secret‑leak detection in CI; consider adding gitleaks or similar.

Overall, the repository includes a full CI pipeline (.github/workflows/*.yml), linting (.golangci.yml), and a permissive LICENSE, indicating disciplined SDLC practices.

The Bottom Line

Moby’s API package offers a rigorously typed, upstream‑aligned surface for Docker Engine interactions, suitable for teams building custom container runtimes or automation tools in Go. The codebase is well‑structured and tested, but the lack of a top‑level Go module and sparse usage documentation require a modest onboarding effort. Ideal for engineering groups that need direct API access and are comfortable managing Go module boundaries.