liveBook · Manning

Container

As explained in Go in Practice, Second Edition

A container is an isolated execution unit that packages an application and its required binaries and libraries while sharing a host operating system kernel.

A container packages an application with its required binaries and libraries inside an isolated execution environment. Unlike a virtual machine, it runs on the host operating system, shares the host kernel, and starts with little boot overhead. section 12.1.2

Use containers to make application environments deterministic and lightweight:

  • Define the binaries and libraries needed to build and run an application, keeping the environment separate from the host. section 12.1.2
  • Run multiple workload instances while avoiding replication of a complete guest operating system for each instance. section 12.1.2
  • Use a container manager on a physical server or virtual machine; the host operating system and hardware enforce isolation. section 12.1.2

Multistage container build for Go

A multistage Docker build separates compilation from runtime packaging: FROM golang:1.22 as build RUN useradd --create-home --shell /bin/bash appbuild RUN mkdir /home/appbuild/bin COPY * /home/appbuild WORKDIR /home/appbuild RUN go build -o /home/appbuild/bin/app /var/appbuild/main.go FROM ubuntu:mantic RUN useradd --create-home --shell /bin/bash apprun COPY --from=build /home/appbuild/bin/app /home/apprun CMD ["/home/apprun/app"] The final image receives the compiled executable from the build stage and runs it without carrying the build environment forward. section 12.1.2

Figure 12.2 Comparing containers to VMs
figure

Compare the replicated guest operating systems of virtual machines with the shared-kernel model of containers. section 12.1.2

How Go in Practice, Second Edition covers it

How deep it goes
Explains shared-kernel isolation, startup behavior, VM differences, deterministic environments, and a multistage Docker build.
Examples
Uses a multistage Dockerfile that compiles a Go executable and copies it into a separate Ubuntu runtime image.
What it assumes
Assumes development and testing are complete before packaging an application for deployment.
What you can do after
Build it from scratch with Docker using separate Go build and runtime stages.
How it connects
Connects containers with Docker, virtual machines, cloud-native applications, horizontal scaling, and cloud deployment.

Also explained in

Compare how 27 books explain container →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Go in Practice, Second Edition. The section links point to the parts of the book it draws on.