-
Namespace isolation: Docker uses Linux namespaces to isolate containers from each other and the host system. Each container gets its own process, network, mount, user, and IPC namespaces.
-
Control groups (cgroups): Docker uses cgroups to limit and allocate resources, such as CPU, memory, and I/O, to containers. This helps prevent a single container from consuming too many resources and affecting other containers or the host system.
-
Capabilities: Docker drops many Linux capabilities by default, limiting the privileges of processes running inside containers. This reduces the potential impact of container breakout or exploitation.
-
Seccomp: Docker uses Seccomp (Secure Computing Mode) profiles to limit the system calls available to containers, reducing the attack surface.
-
AppArmor/SELinux: Docker supports AppArmor and SELinux, which are mandatory access control (MAC) systems that enforce security policies and limit the actions of processes running inside containers.
-
Docker Content Trust: Docker Content Trust provides a mechanism for signing and verifying images, ensuring that the images you use come from trusted sources and have not been tampered with.
-
Use minimal and trusted base images: Start with minimal base images, like Alpine Linux, and use images from trusted sources, such as official repositories or vendors.
-
Keep images up-to-date: Regularly update your images and their dependencies to address security vulnerabilities.
-
Limit container capabilities: Use the
--cap-dropand--cap-addoptions to remove unnecessary capabilities and grant only the required ones to your containers.Example:
docker run --cap-drop=all --cap-add=NET_BIND_SERVICE my-image -
Use read-only file systems: Mount your container's file system as read-only, if possible, to prevent unauthorized modifications.
Example:
docker run --read-only my-image -
Use user namespaces: Enable user namespace remapping to map the root user inside the container to a non-root user on the host system, reducing the risk of privilege escalation.
-
Limit resource usage: Use cgroups to limit the resources available to containers, preventing resource exhaustion attacks.
Example:
docker run --memory=256m --cpus=1 my-image -
Secure container networks: Use network segmentation to isolate containers and restrict communication between them. Apply network policies and firewall rules to control traffic.
-
Enable Docker Content Trust: Enable Docker Content Trust to ensure the integrity and authenticity of images.
Example:
export DOCKER_CONTENT_TRUST=1
c. Scanning images for vulnerabilities:
-
Use Docker Scan: Docker Scan is a built-in vulnerability scanner for Docker images, powered by Snyk. It checks your images for known security vulnerabilities in the base image and its dependencies.
Example:
docker scan my-image -
Use third-party scanners: You can also use third-party scanning tools, like Clair, Anchore Engine, or Aqua Security, to scan your images for vulnerabilities. These tools can provide additional features, like policy enforcement and continuous monitoring.