liveBook · Manning

Container

As explained in Kubernetes in Action, Second Edition

A container is an isolated execution environment that packages an application process with its dependencies while sharing the host operating system kernel.

A container runs an application process in an isolated environment on a host operating system. Unlike a virtual machine, it does not run a separate operating system: its processes share the host kernel. This makes it practical to give each service its own environment without the overhead of a VM, though the isolation is not as strong. section 2.1.1

This is useful when services need different versions of a library or other dependencies. Docker packages an application and its environment as a container image. An image registry stores and shares that image; a container is a running instance created from it. The container gets its filesystem from the image, with other filesystems mountable when needed. section 1.1.3 section 2.1.2

Figure 2.4 The three main Docker concepts are images, registries, and containers.
figure

Use the image–registry–container diagram to distinguish the package, its distribution point, and the process that runs from it. section 2.1.2

Isolation changes what a process can see, not whether it is a host process. Linux namespaces give it a restricted view of resources such as process IDs, filesystems, network interfaces, and hostnames. From inside, it may appear to be alone; from the host, it remains a regular process. Resource limits help prevent one container from consuming resources needed by others. Because containers share a kernel, they are not fully isolated, and most should run without elevated privileges. section 2.3.1 section 2.3.2 section 2.3.4

Inspect a running container

Run `docker exec -it kiada-container sh` to start a shell alongside the application process, then run `ps aux`. The example shows `node app.js`, the shell, and `ps` inside the container; listing processes on the host also reveals the Node.js process. The shell must be present in the image—it may not be included in a production container. section 2.3.2

A container normally has one main process, apart from children it starts. This keeps logs attributable to that process and gives the runtime a clear signal for when the container has stopped. `docker stop kiada-container` signals the main process to shut down; `docker start kiada-container` resumes the stopped container. `docker rm kiada-container` deletes that container and its state, but leaves its image available. section 5.1.1 section 2.2.5

In Kubernetes, a pod—not a container—is the object used to run one or more co-located containers. A Deployment can specify an image as desired state, after which Kubernetes creates the application container in a pod. Put related processes in separate containers within one pod when they must run together; keep independently scalable parts in separate pods. Containers in a pod have separate image-based filesystems. Changes made there are lost when Kubernetes replaces a terminated container, so mount a volume when files must survive replacement. section 3.3.1 section 5.7 section 9.1

Listing 5.1 A basic pod manifest file
apiVersion: v1      #1
kind: Pod      #2
metadata:     
  name: kiada     #3
spec: 
  containers:
  - name: kiada      #4
    image: luksa/kiada:0.1     #5
    ports: 
    - containerPort: 8080      #6

The basic Pod manifest shows where a container’s name, image, and application port belong in a Kubernetes definition. section 5.2.1

How Kubernetes in Action, Second Edition covers it

How deep it goes
Explains images, lifecycle, namespaces, process behavior, and shared-kernel limits; introduces security mechanisms without fully explaining them.
Examples
Uses Docker process-inspection commands, a Node.js application container, and a Kubernetes Pod manifest.
What it assumes
Starts without requiring prior experience with containers, Docker, or Linux.
What you can do after
Operate/configure it with Docker lifecycle commands and Kubernetes Pod definitions, and inspect its processes from inside or outside.
How it connects
Connects containers to virtual machines, container images, image registries, Linux namespaces, pods, Deployments, and volumes.

Also explained in

Compare how 27 books explain container →

Related concepts

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