Securing Containers with Seccomp, AppArmor, and SELinux
Explore Linux kernel security primitives in Docker: syscall filtering with seccomp profiles, mandatory access control with AppArmor, and volume relabeling with SELinux flags.
Published on • November 17, 2026
AI Assistant

Container isolation relies heavily on Linux kernel security primitives. While namespaces partition system views (processes, networks, mounts) and cgroups constrain physical resource consumption (CPU, memory), security frameworks enforce strict operational boundaries.
Docker integrates three primary Linux kernel security mechanisms:
- Seccomp (Secure Computing Mode): Filters system calls made by container processes.
- AppArmor (Application Armor): Path-based Mandatory Access Control (MAC) for filesystem and capabilities protection.
- SELinux (Security-Enhanced Linux): Label-based Mandatory Access Control for objects, process contexts, and volume mounts.
This post explores how each security layer functions, how Docker enforces defaults, and how to configure custom profiles and volume flags.
The Three Layers of Linux Kernel Security in Docker
┌─────────────────────────────────────────────────────────────┐
│ Container Application Process │
└──────────────┬──────────────────────────────┬───────────────┘
│ │
▼ ▼
┌──────────────────────────────┐┌─────────────────────────────┐
│ Seccomp Syscall Filter ││ AppArmor / SELinux (MAC) │
│ Intercepts syscalls before ││ Enforces path and label │
│ kernel execution ││ access controls │
└──────────────┬───────────────┘└──────────────┬──────────────┘
│ │
└──────────────┬───────────────┘
▼
┌─────────────────────────────────────────────────────────────┐
│ Linux Kernel │
└─────────────────────────────────────────────────────────────┘
1. Seccomp: System Call Filtering
Seccomp (Secure Computing Mode) intercepts system calls (syscalls) issued by a container process to the Linux kernel. Modern Linux kernels expose over 300 syscalls. If a vulnerability in an application allows remote code execution (RCE), an attacker might invoke dangerous syscalls (such as reboot, syslog, or kexec_load) to compromise the host.
Docker’s Default Seccomp Profile
By default, Docker applies a seccomp profile to all containers. Out of the ~300+ Linux syscalls, Docker’s default profile blocks approximately 44 high-risk syscalls while allowing standard operational syscalls (read, write, epoll_wait, socket).
Examples of syscalls blocked by default:
reboot: Restricts containers from restarting the physical host.swapon/swapoff: Prevents altering host memory paging.kexec_load: Blocks loading new kernel images.syslog: Prevents reading raw kernel logs.
Running Containers with Seccomp Flags
You can specify seccomp options using the --security-opt CLI flag:
# Verify container runs under default seccomp profile
docker run --rm alpine uname -a
# Run container in unconfined mode (NOT recommended for production)
docker run --rm --security-opt seccomp=unconfined alpine uname -a
# Load a custom seccomp JSON profile
docker run --rm --security-opt seccomp=/path/to/custom-seccomp.json alpine sh
Custom Seccomp Profile Structure
A custom seccomp profile is defined in JSON. It specifies default actions (SCMP_ACT_ERRNO or SCMP_ACT_ALLOW) and rules matching syscall architectures and arguments:
{
"defaultAction": "SCMP_ACT_ERRNO",
"architectures": [
"SCMP_ARCH_X86_64",
"SCMP_ARCH_AARCH64"
],
"syscalls": [
{
"names": [
"read",
"write",
"exit",
"exit_group",
"futex",
"epoll_wait"
],
"action": "SCMP_ACT_ALLOW"
}
]
}
2. AppArmor: Path-Based Mandatory Access Control
AppArmor is a Linux kernel security module utilized by default on Debian and Ubuntu distributions. Unlike Linux permissions (DAC) which rely on user IDs, AppArmor restricts program capabilities and path access based on predefined profiles regardless of process UID.
Docker’s Default AppArmor Profile
When the Docker daemon starts on an AppArmor-enabled host, it automatically generates and loads a default profile named docker-default.
The docker-default profile enforces restrictions such as:
- Preventing writes to
/proc/sysor/syskernel configuration entries. - Restricting raw socket access.
- Restricting mount and umount operations.
- Preventing execution of binary tools inside system mounts.
Inspecting AppArmor Status
Check if AppArmor is loaded on your Linux host:
sudo aa-status
Applying Custom AppArmor Profiles
To apply a custom AppArmor profile to a container:
# Load custom profile onto host kernel
sudo apparmor_parser -r -W /etc/apparmor.d/containers.custom-profile
# Launch container referencing loaded profile
docker run -d --name secure-app \
--security-opt apparmor=containers.custom-profile \
nginx:alpine
3. SELinux: Label-Based Access Control and Volume Relabeling
SELinux (Security-Enhanced Linux) is the default Mandatory Access Control framework on Enterprise Linux distributions such as RHEL, CentOS, Fedora, and Rocky Linux.
SELinux assigns security labels (context strings like user:role:type:sensitivity) to every process, file, and network socket.
SELinux Security Contexts in Docker
When SELinux is enforcing on the host (getenforce returns Enforcing), Docker containers run under a specific context (usually container_t), while host files hold contexts like system_u:object_r:var_t:s0.
If a container attempts to access a host file bind-mounted into /app, SELinux blocks access by default because the container_t process context is forbidden from accessing var_t host files.
Resolving Volume Permission Denied with :z and :Z Flags
To allow SELinux-enforced Docker daemons to grant containers access to host bind mounts, Docker provides volume relabeling flags: :z and :Z.
# Share host directory across MULTIPLE containers (shared context label)
docker run -d -v /var/log/appdata:/app/logs:z nginx:alpine
# Exclusive host directory access for ONE single container (private context label)
docker run -d -v /opt/db-data:/var/lib/mysql:Z mysql:8.0
What :z and :Z do behind the scenes:
:z(Lowercase): Tells Docker to relabel the host path’s SELinux context with a shared content label (z), allowing multiple containers to read and write to the mounted volume safely.:Z(Uppercase): Relabels the host path with an exclusive private context label (Z), ensuring only the current container can access the directory.
⚠️ Warning: Never use
:zor:Zon root host system directories like/etc,/usr, or/var. Doing so relabels host system files, potentially rendering the host OS unbootable or insecure.
Security Comparison Matrix
| Security Feature | Mechanism | Scope | Primary Protection |
|---|---|---|---|
| Seccomp | Syscall filtering | Kernel system calls | Prevents exploit payload execution via kernel vulnerabilities. |
| AppArmor | Path & binary rules | File paths and abilities | Restricts binary capabilities and path writes on Debian/Ubuntu. |
| SELinux | Label-based MAC | Objects & volumes | Controls access boundaries and volume permissions on RHEL/Fedora. |
Takeaway:
Docker protects host systems through multi-layered Linux security primitives. Seccomp filters risky syscalls, AppArmor enforces path-level constraints on Ubuntu/Debian hosts, and SELinux provides label-based object protection on RHEL distributions. When running bind mounts on SELinux systems, always use :z for shared container volumes or :Z for private single-container mounts to avoid permission denial.