Go's standard library does not include a virtualization or cloud orchestration framework. What it gives you are the parts to build one: os/exec to run processes, net/http to talk to control-plane APIs (including over Unix sockets), context for timeouts, and on Linux syscall and os for namespaces and signals. Docker, Kubernetes, containerd, Terraform, and Prometheus are written in Go, and they use their own client libraries on top of these primitives.
In practice you use the standard library for small automation, and official client libraries for real orchestration.
os/execGo compiles to a single static binary, cross-compiles easily, has cheap concurrency for managing many resources, and has a strong HTTP and JSON stack. Those traits suit agents, controllers, CLIs, and operators. The standard library does not abstract hypervisors or clouds, so there is no vm or container package.
| Task | Use |
|---|---|
| Run and supervise processes | os/exec, os/signal |
| Call REST control planes | net/http, encoding/json |
| Talk to a local daemon socket | net or http.Transport with a custom dialer |
| Isolate a process on Linux | syscall.SysProcAttr namespaces |
| Poll and reconcile state | goroutines, time.Ticker, context |
| Structured logs | log/slog |
| Docker, Kubernetes, cloud SDKs | Official modules (docker/docker client, k8s.io/client-go, AWS and GCP SDKs) |
os/execA simple orchestrator often wraps a CLI such as docker, kubectl, or qemu-img. Always use exec.CommandContext so the command is killed when the context expires, and never build commands by concatenating untrusted input into a shell string.
Passing arguments as separate strings avoids shell injection, and Output returns standard output while capturing standard error in the error value.
Docker Engine exposes a REST API on a Unix socket. With net/http you can call it by giving the transport a custom dialer. This example lists containers without any third-party code.
The host name in the URL is ignored, because the dialer always connects to the socket. For anything larger, use the official Docker client module, which handles API versions, streaming, and authentication.
Container runtimes are built on Linux namespaces and cgroups. Go can start a child process in new namespaces through syscall.SysProcAttr. This works on Linux only and normally needs root or user namespaces.
The shell runs with its own hostname, process ID, and mount namespace. A real runtime also sets up cgroups for CPU and memory limits, a root filesystem, networking, and seccomp profiles. Use an existing runtime such as containerd or runc for that instead of rewriting it.
Orchestrators such as Kubernetes work on a reconcile loop: read the desired state, observe the actual state, and act to close the gap. You can express this with a ticker and a context.
Make each action idempotent, add retries with backoff, and handle shutdown signals with signal.NotifyContext. For Kubernetes controllers use controller-runtime and client-go, which add caching, watches, and leader election.
No. Use official client libraries (Docker, containerd, libvirt bindings, cloud SDKs) or call CLI tools with os/exec.
Go produces portable static binaries and handles many concurrent connections and watchers cheaply, which fits daemons and controllers.
Yes, with controller-runtime or the Operator SDK, which build on client-go.
No. Linux namespaces are a Linux kernel feature, so guard such code with a linux build tag.
Go's standard library supplies the primitives for virtualization and orchestration tooling, not a framework. Use os/exec and context for process control, net/http for APIs, syscall for Linux namespaces, and reconcile loops for desired-state management. For production work, rely on the official Docker, containerd, and Kubernetes client libraries.