SyntaxPilot
Courses/Cybersecurity Fundamentals/Lesson 67
Video coming soonThis lesson’s video is being made

Start with the notes below; the video appears here as soon as it is on YouTube.

Cybersecurity Fundamentals · Lesson 67 of 90

Container security

container vs virtual machinenamespacescgroupsimages and layersbase imagesminimal and distroless imagesimage scanningimage signingrunning as non-rootread-only root filesystemLinux capabilitiesseccompAppArmorSELinux

These are the notes for Cybersecurity Fundamentals (defensive), episode 67. In episode 66 golden images kept virtual machines clean. Most modern apps, though, ship as containers. This episode builds container security from zero: what a container really is, what keeps containers apart, how image layers leak secrets, how to trust the image you deploy, and how to take power away from a container while it runs. Every term is defined the first time it appears; the Glossary collects them.

Scope. Defensive and educational only. Every program is a small toy simulation written for this lesson; nothing real is attacked, and the passwords are fake. Samples were run on 13 Nov 2026 in the SyntaxPilot compiler (Python 3.13).

Step 1: what a container really is

Real-life example: independent houses vs flats in one building. Each house has its own foundation; flats share one foundation, and walls plus a separate electricity meter keep families private and fair.

  • Kernel: the core of an operating system. It controls memory, files, processes and hardware. Programs ask it for everything.
  • Process: a running program. Your browser, a Python script, a database server: each is one or more processes.
  • Virtual machine (VM): a whole computer simulated in software, with its own full operating system and its own kernel, running on a hypervisor (software that shares one physical machine between VMs). Like an independent house.
  • Container: an app packed with everything it needs (libraries, settings, files) that runs as an ordinary process on the host, sharing the host's kernel. Like a flat. Containers start in about a second and are small, but they share the foundation, so isolation matters even more.
  • Host: the machine (physical or virtual) the containers run on.
Virtual machine Container
Kernel its own shares the host's
Size gigabytes (whole OS) megabytes (app + libraries)
Start time tens of seconds to minutes about a second
Isolation hypervisor, strong kernel features: namespaces, cgroups, and more
Risk if broken escape to hypervisor (rare) container escape to the host kernel

Demo 1: namespaces

Two apps, a shop and a payroll system, share one machine.

# Two apps on one machine. Without namespaces every process sees every other.
procs = [  # (pid, owner app, command)
  (101, "shop",    "python shop.py"),
  (102, "shop",    "worker --orders"),
  (201, "payroll", "java Payroll"),
  (202, "payroll", "db --salaries"),
]
def ps(viewer, namespaces):
    seen = [p for p in procs if not namespaces or p[1] == viewer]
    if namespaces:   # inside its own PID namespace, numbering restarts at 1
        seen = [(i, app, cmd) for i, (_, app, cmd) in enumerate(seen, 1)]
    return seen

for ns in (False, True):
    view = ps("shop", ns)
    print("namespaces", "ON: " if ns else "OFF:", "shop runs ps")
    for pid, app, cmd in view:
        print(f"   pid {pid:<4} {cmd}")
    print("   shop can kill:", [c for _, a, c in view if a != "shop"])

Output:

namespaces OFF: shop runs ps
   pid 101  python shop.py
   pid 102  worker --orders
   pid 201  java Payroll
   pid 202  db --salaries
   shop can kill: ['java Payroll', 'db --salaries']
namespaces ON:  shop runs ps
   pid 1    python shop.py
   pid 2    worker --orders
   shop can kill: []
  • ps: the command that lists processes.
  • PID (process ID): the number the kernel gives each process.
  • Namespace (Linux): a kernel feature that gives a process its own private view of one kind of system resource. Main kinds: PID (its own process list, numbered from 1), network (its own network interfaces and ports), mount (its own file system view), UTS (its own hostname), IPC (its own inter-process communication), user (its own user IDs, so root inside can map to an ordinary user outside).
  • Docker's security documentation: processes running within a container "cannot see, and even less affect, processes running in another container."

Demo 2: cgroups

# One machine, 8 GB of memory, three containers. One has a memory leak.
HOST_MB = 8192
def run(limits):
    used = {"shop": 900, "payroll": 700, "leaky": 0}
    for minute in range(1, 7):
        used["leaky"] += 1600                      # leaks 1.6 GB a minute
        if limits and used["leaky"] > limits["leaky"]:
            return f"minute {minute}: leaky hit its 2 GB limit -> only leaky restarted"
        if sum(used.values()) > HOST_MB:
            return f"minute {minute}: host out of memory -> shop and payroll killed too"
    return "fine"

print("no limits:  ", run(None))
print("with cgroup:", run({"leaky": 2048}))

Output:

no limits:   minute 5: host out of memory -> shop and payroll killed too
with cgroup: minute 2: leaky hit its 2 GB limit -> only leaky restarted
  • Memory leak: a bug where a program keeps taking memory and never gives it back.
  • cgroup (control group): a Linux kernel feature that measures and limits how much CPU, memory, disk I/O and number of processes a group of processes may use. Docker's documentation: cgroups "implement resource accounting and limiting" and ensure "that a single container cannot bring the system down by exhausting one of those resources."
  • In Docker you set limits with options such as --memory 2g and --cpus 1; in Kubernetes with resources.limits.
  • Without limits, one buggy (or attacked) container causes a denial of service (episode 23) for every neighbour.

Namespaces = walls (what you can see). cgroups = meters (how much you can use). Neither one alone makes a container safe; later steps add more layers.

Step 2: images and layers

  • Container image: a read-only template that holds the app and its files; a container starts from it.
  • Dockerfile: a text recipe for building an image; each line (instruction) is one step: FROM, COPY, RUN, USER, CMD.
  • Layer: each build step adds a read-only layer on top of the previous ones, like sheets of tracing paper stacked up. The final file system is the stack seen from the top.
  • Base image: the first layer, named by FROM: the starting operating-system files (for example a Debian-based Python image).
  • Writable layer: a running container is the image plus a thin writable layer on top; changes the container makes go there and vanish with it.
  • Rule: layers are never edited, only added.

Demo 3: the secret in layer 2

# An image is a stack of read-only layers. Each Dockerfile step adds one.
layers = [
  ("FROM python:3.13-slim",  {"/usr/bin/python3": "...", "/etc/os-release": "debian"}),
  ("COPY .env /app/.env",    {"/app/.env": "DB_PASSWORD=Fake-Pa55"}),
  ("COPY app.py /app/",      {"/app/app.py": "print('shop')"}),
  ("RUN rm /app/.env",       {"/app/.env": None}),   # a 'whiteout': hides the file
]
def final_view(layers):                     # what the running container sees
    fs = {}
    for _, changes in layers:
        for path, data in changes.items():
            if data is None: fs.pop(path, None)
            else: fs[path] = data
    return fs

print("container sees .env? ", "/app/.env" in final_view(layers))
for n, (step, changes) in enumerate(layers, 1):   # anyone who pulls the image
    if changes.get("/app/.env"):
        print(f"but layer {n} ({step}) still holds:", changes["/app/.env"])

Output:

container sees .env?  False
but layer 2 (COPY .env /app/.env) still holds: DB_PASSWORD=Fake-Pa55
  • .env file: a file holding configuration such as passwords for an app.
  • Whiteout: the marker a later layer adds to hide a file from an earlier layer. The file is hidden, not deleted: anyone who can pull the image can unpack layer 2 (images are just archives of layers) and read it.
  • Fix: never copy secrets into an image, not even for one step. Give secrets to the container at runtime (from a secrets manager, episode 65, or the orchestrator's secret store), or use a build secret mount (RUN --mount=type=secret,...) which is available during one step and never becomes a layer. If a secret ever reached an image, treat it as leaked: rotate it.

Step 3: smaller images and image scanning

  • CVE: a publicly listed, known vulnerability (episode 8).
  • Attack surface (episode 1): everything an attacker could try. Every extra package in an image adds to it.

Demo 4: a toy image scanner

The CVE counts are made up for the demo; the point is the trend.

# A toy image scanner. The CVE counts are made up for the demo.
CVES = {"openssl": 4, "curl": 3, "bash": 1, "perl": 2,
        "apt": 1, "tar": 1, "glibc": 2, "python": 0}
images = {
  "full OS base": ["openssl", "curl", "bash", "perl", "apt", "tar", "glibc", "python"],
  "slim base":    ["openssl", "bash", "apt", "glibc", "python"],
  "distroless":   ["glibc", "python"],
}
for name, pkgs in images.items():
    found = sum(CVES[p] for p in pkgs)
    shell = "yes" if "bash" in pkgs else "no"
    print(f"{name:13} {len(pkgs)} packages  {found:2} known CVEs  shell: {shell}")

Output:

full OS base  8 packages  14 known CVEs  shell: yes
slim base     5 packages   8 known CVEs  shell: yes
distroless    2 packages   2 known CVEs  shell: no
  • Image scanning: reading every package in an image and matching it against vulnerability databases, usually in the CI pipeline (episode 60) and again in the registry on push. Fail the build on critical findings that have a fix.
  • Trivy (by Aqua Security): an open-source scanner. Its README lists targets (container images, file systems, Git repositories, VM images, Kubernetes) and findings (CVE vulnerabilities, IaC misconfigurations, exposed secrets, licences, and SBOMs).
  • SBOM (software bill of materials): a list of every component inside a piece of software (episode 62).
  • Minimal image / slim image: a base image with only a small set of packages.
  • Distroless image: from Google's distroless project, images that contain "only your application and its runtime dependencies", without "package managers, shells or any other programs". The project notes this "improves the signal to noise of scanners". No shell also means an attacker who gets in has no tools to work with.
  • Package manager: the tool that installs software in an OS (apt, apk, yum). In a runtime image it is only useful to an attacker.

Step 4: trusting the image

  • Registry: a server that stores and hands out images (like an app store for containers): Docker Hub, or a private registry in your cloud.
  • Tag: a human-readable name for an image, like shop:latest or shop:1.4. Tags can be moved to point at a different image.
  • Digest: the SHA-256 hash (episode 13) of the image content, like sha256:56edd4.... Change one byte and the digest changes; a digest can never point at different content.

Demo 5: tags vs digests

# A registry maps tags (names) to image content. Tags can be MOVED; digests can't.
import hashlib
def digest(content): return "sha256:" + hashlib.sha256(content).hexdigest()[:12]

good = b"shop v1.4: reviewed, scanned, signed"
registry = {"shop:latest": good}
approved = digest(good)                 # recorded by the pipeline at release
print("approved digest:", approved)

registry["shop:latest"] = b"shop v1.4 + hidden cryptominer"   # stolen push token

pulled = registry["shop:latest"]
print("deploy by tag:    got", digest(pulled), "-> runs it anyway")
ok = digest(pulled) == approved
print("deploy by digest:", "OK" if ok else "REFUSED: content does not match")

Output:

approved digest: sha256:56edd41d71f0
deploy by tag:    got sha256:182efd50cb07 -> runs it anyway
deploy by digest: REFUSED: content does not match
  • Cryptominer: malware that secretly uses your computers to mine cryptocurrency (episode 5's cryptojacker).
  • Pin by digest: deploy image@sha256:... in production, not a tag.
  • Immutable tags: a registry setting that refuses to overwrite an existing tag.

Image signing

Real-life example: a medicine strip. The batch number says exactly which batch (digest); the maker's seal and hologram prove who made it (signature); buying from a licensed chemist means controlled stock (registry security).

  • Image signing: the pipeline signs the image digest with a private key; the cluster verifies the signature before running it (digital signatures, episode 16). A digest proves what; a signature proves who.
  • Sigstore / cosign: Sigstore's documentation: "Cosign is a command line utility that can sign and verify software artifact, such as container images and blobs." In keyless mode cosign gets a short-lived certificate from Fulcio, a certificate authority that checks your identity through OpenID Connect (a standard login protocol), and the signing is recorded in Rekor, Sigstore's public transparency log (an append-only public record anyone can check).
  • Registry security: a private registry; push rights only for the pipeline; short-lived credentials (a stolen long-lived push token is how Demo 5 happened); scan on push; immutable tags; only signed images allowed to deploy.

Step 5: less power inside the container

  • Root: the all-powerful administrator user on Linux (user ID 0). By default many images run their app as root.
  • Linux capabilities: root's power split into separate permissions, for example CAP_CHOWN (change file owners), CAP_NET_ADMIN (change network settings), CAP_SYS_MODULE (load kernel modules), CAP_SYS_ADMIN (a very broad one), CAP_NET_BIND_SERVICE (use ports below 1024). A process gets only the capabilities it is given.
  • Docker's documentation: Docker starts containers with a restricted set of capabilities, it "drops all capabilities except those needed", so root inside a container has fewer privileges than real root on the host.
  • Privileged container (--privileged): gives the container almost all capabilities and device access, turning most isolation off. Avoid it.

Demo 6: root, capabilities and a read-only filesystem

# Root is not one power but many: Linux capabilities. Which actions succeed?
ACTIONS = {           # short name: the power it needs (None = anyone can)
  "port":   None,            # serve the shop on port 8080
  "chown":  "CHOWN",         # change who owns a file
  "module": "SYS_MODULE",    # load code into the host kernel
  "net":    "NET_ADMIN",     # change network settings
  "write":  "WRITE_ROOTFS",  # write /usr/bin (plant a tool)
}
setups = {
  "root, privileged":     {"CHOWN", "SYS_MODULE", "NET_ADMIN", "WRITE_ROOTFS"},
  "root, default caps":   {"CHOWN", "WRITE_ROOTFS"},
  "non-root, no caps, ro": set(),
}
print(f"{'setup':22}", *(f"{a:7}" for a in ACTIONS))
for name, powers in setups.items():
    row = ["ok" if need is None or need in powers else "-" for need in ACTIONS.values()]
    print(f"{name:22}", *(f"{r:7}" for r in row))

Output:

setup                  port    chown   module  net     write  
root, privileged       ok      ok      ok      ok      ok     
root, default caps     ok      ok      -       -       ok     
non-root, no caps, ro  ok      -       -       -       -

(WRITE_ROOTFS is not a real capability; in the toy it stands for "the root filesystem is writable", which is a separate setting.)

  • Non-root user: run the app as an ordinary user, with USER 10001 in the Dockerfile or runAsNonRoot in Kubernetes.
  • Drop all capabilities, add back only what's needed: docker run --cap-drop ALL --cap-add NET_BIND_SERVICE ....
  • Read-only root filesystem (--read-only, with a small writable temporary directory if the app needs one): an attacker can't download tools or change the app's files.
  • no-new-privileges (--security-opt no-new-privileges): stops a process from gaining more privileges later (for example through setuid programs, episode 9).

Step 6: kernel filters

  • System call (syscall): a request a program makes to the kernel: read, write, openat (open a file), socket (open a network connection), mount (attach a file system), unshare (create new namespaces), init_module (load a kernel module). Linux has more than 300.

Demo 7: seccomp

# seccomp: the kernel checks every system call against an allowlist.
ALLOW = {"read", "write", "openat", "close", "socket", "accept", "futex", "exit"}

def kernel(proc, calls, profile):
    for call in calls:
        if profile is None or call in ALLOW:
            print(f"  {proc}: {call:12} allowed")
        else:
            print(f"  {proc}: {call:12} EPERM (Operation not permitted)")

web = ["openat", "read", "socket", "accept", "write"]
attack = ["read", "unshare", "mount", "init_module"]   # trying to leave the box
print("no seccomp profile:");      kernel("hijacked", attack, None)
print("default-style profile:");   kernel("hijacked", attack, ALLOW)
print("the real web app, same profile:", all(c in ALLOW for c in web))

Output:

no seccomp profile:
  hijacked: read         allowed
  hijacked: unshare      allowed
  hijacked: mount        allowed
  hijacked: init_module  allowed
default-style profile:
  hijacked: read         allowed
  hijacked: unshare      EPERM (Operation not permitted)
  hijacked: mount        EPERM (Operation not permitted)
  hijacked: init_module  EPERM (Operation not permitted)
the real web app, same profile: True
  • seccomp (secure computing mode): a Linux feature that filters a process's system calls. Docker's documentation: the default seccomp profile is "an allowlist that denies access to system calls by default" and "disables around 44 system calls out of 300+", while keeping wide application compatibility.
  • EPERM: the error code for "Operation not permitted", returned when a call is refused.
  • Unconfined: running with no seccomp profile. Don't.
  • Allowlist vs denylist (episode 24): an allowlist names what is allowed and blocks the rest; a denylist names what is blocked and allows the rest. Allowlists are safer.

AppArmor and SELinux

  • Mandatory access control (MAC): access rules set centrally by the administrator that even root inside the container must obey. Compare discretionary access control (DAC): normal file permissions, which a file's owner can change.
  • AppArmor: a Linux MAC system that gives each program a profile listing which files it may read or write and which actions it may take.
  • SELinux (Security-Enhanced Linux): a Linux MAC system that puts a label on every process and file; a policy decides which labels may interact.

Container escape (concept only)

  • Container escape: breaking out of a container's isolation to control the host, and with it every other container. We cover it only as a concept: what makes it possible and how to prevent it.
  • Common causes: a privileged container; mounting the Docker socket (/var/run/docker.sock) into a container, which hands that container control of the Docker daemon; mounting sensitive host paths; dangerous capabilities like CAP_SYS_ADMIN; and kernel vulnerabilities, since every container shares the host kernel.
  • Docker daemon: the background service that builds and runs containers; it runs as root on the host. Docker's documentation: "only trusted users should be allowed to control your Docker daemon."
  • Defence: all the layers together: non-root, no capabilities, seccomp, AppArmor or SELinux, no privileged mode, no Docker socket, read-only filesystem, a patched host kernel, and rootless container engines where possible.

Step 7: Dockerfile best practices

Demo 8: a toy Dockerfile linter

# A toy Dockerfile linter: check the recipe before building the image.
DOCKERFILE = """FROM python:latest
COPY . /app
RUN pip install -r /app/requirements.txt
ENV DB_PASSWORD=Fake-Pa55
EXPOSE 22
CMD python /app/shop.py"""
RULES = [
  (lambda l: l.startswith("FROM") and (":latest" in l or ":" not in l),
       "pin the base image version (or digest), not :latest"),
  (lambda l: l.startswith("COPY . "), "COPY . copies everything: use .dockerignore"),
  (lambda l: "PASSWORD" in l.upper() and l.startswith(("ENV", "ARG")),
       "secret baked into the image: use a secret mount"),
  (lambda l: l.startswith("EXPOSE 22"), "no SSH inside containers"),
]
lines = DOCKERFILE.splitlines()
for n, line in enumerate(lines, 1):
    for broken, advice in RULES:
        if broken(line): print(f"line {n}: {advice}")
if not any(l.startswith("USER") for l in lines):
    print("end:    no USER line -> runs as root; add USER 10001")

Output:

line 1: pin the base image version (or digest), not :latest
line 2: COPY . copies everything: use .dockerignore
line 4: secret baked into the image: use a secret mount
line 5: no SSH inside containers
end:    no USER line -> runs as root; add USER 10001
  • Linter: a tool that checks code (here, a Dockerfile) for mistakes and bad practices without running it. hadolint describes itself as a "Dockerfile linter, validate inline bash, written in Haskell"; Trivy also checks Dockerfiles for misconfigurations.
  • .dockerignore: a file listing what COPY . must skip (.env, .git, test data).

The fixed Dockerfile (a multi-stage build: the first stage installs dependencies, the final image copies only the results onto a minimal base):

FROM python:3.13-slim AS build
COPY requirements.txt .
RUN pip install --target=/deps -r requirements.txt

FROM <distroless-python-image>@sha256:<digest>
COPY --from=build /deps /deps
COPY shop.py /app/
USER 10001
CMD ["/app/shop.py"]

(Replace the placeholders with the distroless Python image and digest your team has approved; the final stage also needs PYTHONPATH=/deps or equivalent so Python finds the libraries.)

And run it with the runtime settings from steps 5-6:

docker run --read-only --cap-drop ALL --security-opt no-new-privileges \
  --memory 512m --cpus 1 --user 10001 shop@sha256:<digest>

Checklist:

  1. Pin the base image to a version, and deploy by digest.
  2. Use a minimal or distroless base; multi-stage builds.
  3. Copy only what you need; use .dockerignore.
  4. No secrets in the Dockerfile, the build context or any layer.
  5. A non-root USER.
  6. No SSH server, no package manager or shell in the final image when possible.
  7. Scan and lint in the pipeline; sign the image.
  8. Run read-only, drop all capabilities, keep seccomp and AppArmor/SELinux on, set cgroup limits.

The whole chain

  1. Apps see and kill each other → namespaces.
  2. One leak starves the host → cgroups.
  3. Deleted secret still in a layer → no secrets in images, runtime secrets.
  4. Full OS full of CVEs → distroless / minimal images, image scanning.
  5. Tag moved to a bad image → digests, image signing, registry security.
  6. Root in the box → non-root, drop capabilities, read-only rootfs.
  7. Dangerous syscalls → seccomp, AppArmor, SELinux; together they prevent container escape.

Common mistakes (and the fix)

Mistake What you see Why Fix
COPY .env then RUN rm .env but layer 2 (COPY .env /app/.env) still holds: DB_PASSWORD=Fake-Pa55 layers are only added runtime secrets or a build secret mount; rotate the leaked secret
FROM python:latest a different base image on every build tags move pin a version; deploy by digest
deploying shop:latest deploy by tag: got sha256:182efd50cb07 -> runs it anyway the tag was moved pin digests, immutable tags, verify signatures
full OS base image full OS base 8 packages 14 known CVEs shell: yes (toy numbers) packages the app never uses minimal or distroless base, scan in CI
docker run --privileged 5/5 actions allowed in Demo 6 disables most isolation drop ALL capabilities, add only what's needed
no USER line end: no USER line -> runs as root; add USER 10001 root by default non-root user
-v /var/run/docker.sock:/var/run/docker.sock the container controls the Docker daemon the daemon is root on the host never mount the Docker socket
no memory limit minute 5: host out of memory -> shop and payroll killed too no cgroup limit --memory, --cpus, Kubernetes limits
--security-opt seccomp=unconfined dangerous syscalls allowed no syscall filter keep the default profile or a stricter one

Mini project: a container security checker

Write one Python program that takes a description of a container as a dictionary (image, user, privileged, cap_add, cap_drop, read_only, seccomp, mounts, memory_limit) and prints a report with a score out of 10. Rules: image pinned by digest, non-root user, not privileged, capabilities dropped (ALL), read-only root filesystem, a seccomp profile, no docker.sock mount, a memory limit. Test it on a "bad" container and a "good" one.

Practice

1. Add a mount namespace to the toy ps demo: each app should see only its own files.

Solution
files = {"shop": ["/app/shop.py"], "payroll": ["/app/Payroll.jar", "/data/salaries.db"]}
def ls(viewer, namespaces):
    return files[viewer] if namespaces else [f for fs in files.values() for f in fs]
print(ls("shop", False))   # sees payroll's salary database too
print(ls("shop", True))    # ['/app/shop.py']

2. Give every container in the cgroup toy its own limit, and make the leaky one leak faster. What changes?

Solution

Change the check to loop over every container: for name, mb in used.items(): if limits and mb > limits[name]: .... With limits on all three, whichever exceeds its own limit is restarted alone; the host never runs out of memory as long as the limits add up to less than the host's memory.

3. Add a rule to the toy linter: ADD with a URL downloads files at build time without checking them.

Solution
RULES.append((lambda l: l.startswith("ADD http"),
              "ADD from a URL: download with a checksum check, or COPY a verified file"))

4. Make the seccomp toy count how many calls were blocked.

Solution
def kernel(proc, calls, profile):
    blocked = [c for c in calls if profile is not None and c not in ALLOW]
    print(f"  {proc}: {len(blocked)} of {len(calls)} calls blocked: {blocked}")

5. In the layers demo, how could the developer have passed the password without it ever being in a layer?

Solution

At runtime: docker run -e DB_PASSWORD_FILE=/run/secrets/db ... with the secret mounted by the orchestrator, or from a secrets manager. If it is needed during the build: RUN --mount=type=secret,id=db ..., which makes it available to that one step only and never stores it in a layer.

6. Why is a container with no shell harder to attack after a break-in?

Solution

Most follow-up steps (downloading tools, exploring the file system, running scripts) need a shell and utilities like curl. A distroless image has none, so the attacker is limited to what the app itself can do.

Quick quiz

A: yes, the file was deleted
B: no, it is still inside the earlier layer
C: yes, if the container is non-root
D: only if the image is distroless

A Dockerfile copies .env, then a later step runs rm .env. Is the secret safe?

Answer

B. Image layers are only ever added. The rm step adds a whiteout that hides the file in the final view, but the COPY layer still contains it, and anyone who can pull the image can read it. Rotate the secret.

Interview questions

  1. Container vs virtual machine? A VM has its own kernel on a hypervisor; a container is an isolated process sharing the host kernel. Containers are lighter but a kernel bug affects every container.
  2. What do namespaces and cgroups do? Namespaces limit what a process can see (processes, network, mounts, users); cgroups limit how much it can use (CPU, memory, I/O, PIDs).
  3. Why can a deleted file still be in an image? Layers are immutable; a later delete only adds a whiteout. The earlier layer still holds the file.
  4. Why use distroless or minimal images? Fewer packages means fewer CVEs, less scanner noise, and no shell or package manager for an attacker.
  5. Tag vs digest? A tag is a movable name; a digest is the SHA-256 of the content and identifies exactly one image. Pin production to digests.
  6. How does image signing help? It proves who built the image; the cluster refuses images without a valid signature from the expected identity (cosign, keyless with Fulcio and Rekor).
  7. What are Linux capabilities? Root's powers split into separate permissions; drop all and add back only what the app needs.
  8. What does seccomp do? Filters system calls with an allowlist; Docker's default profile blocks around 44 of 300+.
  9. AppArmor vs SELinux? Both are mandatory access control: AppArmor uses per-program path-based profiles, SELinux uses labels and a policy.
  10. What causes container escape and how do you prevent it? Privileged containers, a mounted Docker socket, sensitive host mounts, broad capabilities, kernel bugs. Prevent with non-root, dropped capabilities, seccomp, MAC, no privileged mode or socket mounts, and a patched host.

Glossary

Term Meaning
kernel the core of an operating system; controls memory, files, processes, hardware
process a running program
PID process ID, the number the kernel gives each process
virtual machine (VM) a whole computer simulated in software, with its own OS and kernel
hypervisor software that runs and separates virtual machines on one physical machine
container an app with its libraries, running as an isolated process that shares the host kernel
host the machine containers run on
namespace (Linux) a private view of one system resource: PID, network, mount, UTS, IPC, user
cgroup (control group) a kernel feature that measures and limits CPU, memory, I/O and process counts
memory leak a bug that keeps taking memory and never frees it
container image a read-only template a container starts from
Dockerfile a text recipe for building an image, one instruction per step
layer a read-only set of file changes added by one build step
base image the first layer, named by FROM
whiteout a marker that hides a file from an earlier layer without removing it
build secret mount a way to give a secret to one build step without storing it in a layer
CVE a publicly listed known vulnerability
attack surface everything an attacker could try to use
image scanning matching an image's packages against vulnerability databases
Trivy an open-source scanner for images, file systems, repos and Kubernetes
SBOM software bill of materials: a list of all components
minimal / slim image a base image with few packages
distroless image an image with only the app and its runtime dependencies, no shell or package manager
package manager the tool that installs software in an OS (apt, apk, yum)
registry a server that stores and serves container images
tag a movable name for an image (shop:latest)
digest the SHA-256 hash of an image's content
immutable tag a registry setting that refuses to overwrite a tag
cryptominer malware that secretly mines cryptocurrency on your machines
image signing signing an image digest so others can verify who built it
cosign Sigstore's tool to sign and verify container images and other artifacts
Fulcio Sigstore's certificate authority for short-lived signing certificates
OpenID Connect a standard login protocol used to prove identity
Rekor Sigstore's public transparency log of signatures
transparency log an append-only public record anyone can check
root the all-powerful Linux administrator (user ID 0)
Linux capabilities root's powers split into separate permissions (CHOWN, NET_ADMIN, SYS_MODULE...)
privileged container a container with almost all capabilities and device access; little isolation
non-root user running the app as an ordinary user (USER 10001)
read-only root filesystem a container whose files can't be changed at runtime
no-new-privileges a setting that stops a process gaining more privileges later
system call (syscall) a request a program makes to the kernel
seccomp secure computing mode: a kernel filter on system calls
EPERM "Operation not permitted", the error for a refused call
unconfined running without a seccomp (or MAC) profile
allowlist / denylist name what's allowed (block the rest) / name what's blocked (allow the rest)
mandatory access control (MAC) central rules even root must obey
discretionary access control (DAC) normal permissions the owner can change
AppArmor Linux MAC with per-program profiles
SELinux Security-Enhanced Linux: MAC with labels and a policy
container escape breaking out of a container to control the host
Docker daemon the background service that runs containers, as root
Docker socket /var/run/docker.sock, the door to control the Docker daemon
rootless mode running the container engine itself as a non-root user
linter a tool that checks code for mistakes without running it
hadolint a Dockerfile linter
.dockerignore a file listing what the build must not copy
multi-stage build a Dockerfile with a build stage and a smaller final stage

Summary

  • A container is a process sharing the host kernel; namespaces limit what it sees, cgroups limit what it uses.
  • Images are stacks of read-only layers: never put secrets in them.
  • Use minimal or distroless images and scan them in the pipeline.
  • Deploy by digest, sign images and verify signatures, and lock down the registry.
  • Run non-root, drop all capabilities, use a read-only filesystem, keep seccomp and AppArmor/SELinux on.
  • Never run privileged or mount the Docker socket; together the layers prevent container escape.
  • Next episode: Kubernetes security.

Sources (fetched 13 Nov 2026)

  • Docker docs, Docker Engine security: https://docs.docker.com/engine/security/
  • Docker docs, Seccomp security profiles for Docker: https://docs.docker.com/engine/security/seccomp/
  • GoogleContainerTools/distroless README: https://github.com/GoogleContainerTools/distroless
  • aquasecurity/trivy README: https://github.com/aquasecurity/trivy
  • Sigstore docs, cosign quickstart: https://docs.sigstore.dev/signing/quickstart
  • hadolint project: https://github.com/hadolint/hadolint