[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M79NKPGWTHDA2D7706KPN9V0":3,"skill-same:01M79NKPGWTHDA2D7706KPN9V0":43},{"skillNo":4,"name":5,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":7,"ownerLogin":8,"ownerAvatarUrl":9,"ownerAccountNo":10,"ownerDisplayName":11,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":15,"categories":16,"keywords":17,"publishedAt":18,"linkOnly":19,"markdownContent":20,"markdownBody":20,"frontMatter":21,"refName":22,"commitSha":23,"skillDirectory":24,"forksCount":13,"repositoryHtmlUrl":25,"repositoryHomepageUrl":6,"ownerHtmlUrl":26,"ownerBlogUrl":6,"ownerDescription":27,"updatedAt":28,"install":29,"resources":42},"01M79NKPGWTHDA2D7706KPN9V0","docker-security-cheat-sheet",null,"JunMystery\u002FAgent-Guidance","JunMystery","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F161468934?v=4","01M79MTMV8F0BY8NK1A92RA8A0","Jun","01M79MTMWCFBKPHN5B25E6V20B",0,"MIT","https:\u002F\u002Fgithub.com\u002FJunMystery\u002FAgent-Guidance\u002Fblob\u002Fmain\u002Fskills\u002Fdocker-security-cheat-sheet\u002FSKILL.md",[],[],"2026-11-15 14:19:17",false,"# Docker Security Cheat Sheet\n\n## Introduction\n\nDocker is the most popular containerization technology. When used correctly, it can enhance security compared to running applications directly on the host system. However, certain misconfigurations can reduce security levels or introduce new vulnerabilities.\n\nThe aim of this cheat sheet is to provide a straightforward list of common security errors and best practices to assist in securing your Docker containers.\n\n## Rules\n\n### RULE \\#0 - Keep Host and Docker up to date\n\nTo protect against known container escape vulnerabilities like [Leaky Vessels](https:\u002F\u002Fsnyk.io\u002Fblog\u002Fcve-2024-21626-runc-process-cwd-container-breakout\u002F), which typically result in the attacker gaining root access to the host, it's vital to keep both the host and Docker up to date. This includes regularly updating the host kernel as well as the Docker Engine.\n\nThis is due to the fact that containers share the host's kernel. If the host's kernel is vulnerable, the containers are also vulnerable. For example, the kernel privilege escalation exploit, [Dirty COW](https:\u002F\u002Fgithub.com\u002Fscumjr\u002Fdirtycow-vdso), executed inside a well-insulated container would still result in root access on a vulnerable host.\n\n### RULE \\#1 - Do not expose the Docker daemon socket (even to the containers)\n\nDocker socket _\u002Fvar\u002Frun\u002Fdocker.sock_ is the UNIX socket that Docker is listening to. This is the primary entry point for the Docker API. The owner of this socket is root. Giving someone access to it is equivalent to giving unrestricted root access to your host.\n\n**Do not enable _tcp_ Docker daemon socket.** If you are running docker daemon with `-H tcp:\u002F\u002F0.0.0.0:XXX` or similar you are exposing unencrypted and unauthenticated direct access to the Docker daemon, if the host is internet connected this means the docker daemon on your computer can be used by anyone from the public internet.\nIf you really, **really** have to do this, you should secure it. Check how to do this following [Docker official documentation](https:\u002F\u002Fdocs.docker.com\u002Fengine\u002Freference\u002Fcommandline\u002Fdockerd\u002F#daemon-socket-option).\n\n**Do not expose _\u002Fvar\u002Frun\u002Fdocker.sock_ to other containers**. If you are running your docker image with `-v \u002Fvar\u002Frun\u002Fdocker.sock:\u002F\u002Fvar\u002Frun\u002Fdocker.sock` or similar, you should change it. Mounting the socket read-only does not make the Docker API read-only: a process that can connect to the socket can still send requests that modify containers or the host. Docker grants access to all daemon commands by default; filesystem mount flags do not replace [API authorization](https:\u002F\u002Fdocs.docker.com\u002Fengine\u002Fextend\u002Fplugins_authorization\u002F). Equivalent in the docker compose file is something like this:\n\n```yaml\nvolumes:\n  - \"\u002Fvar\u002Frun\u002Fdocker.sock:\u002Fvar\u002Frun\u002Fdocker.sock\"\n```\n\n### RULE \\#2 - Set a user\n\nConfiguring the container to use an unprivileged user is the best way to prevent privilege escalation attacks. This can be accomplished in three different ways as follows:\n\n1. During runtime using `-u` option of `docker run` command e.g.:\n\n```bash\ndocker run -u 4000 alpine\n```\n\n2. During build time. Simply add user in Dockerfile and use it. For example:\n\n```dockerfile\nFROM alpine\nRUN groupadd -r myuser && useradd -r -g myuser myuser\n#    \u003CHERE DO WHAT YOU HAVE TO DO AS A ROOT USER LIKE INSTALLING PACKAGES ETC.>\nUSER myuser\n```\n\n3. Enable user namespace support (`--userns-remap=default`) in [Docker daemon](https:\u002F\u002Fdocs.docker.com\u002Fengine\u002Fsecurity\u002Fuserns-remap\u002F#enable-userns-remap-on-the-daemon)\n\nMore information about this topic can be found at [Docker official documentation](https:\u002F\u002Fdocs.docker.com\u002Fengine\u002Fsecurity\u002Fuserns-remap\u002F). For additional security, you can also run in rootless mode, which is discussed in [Rule \\#11](#rule-11---run-docker-in-rootless-mode).\n\nIn Kubernetes, this can be configured in [Security Context](https:\u002F\u002Fkubernetes.io\u002Fdocs\u002Ftasks\u002Fconfigure-pod-container\u002Fsecurity-context\u002F) using the `runAsUser` field with the user ID e.g:\n\n```yaml\napiVersion: v1\nkind: Pod\nmetadata:\n  name: example\nspec:\n  containers:\n    - name: example\n      image: gcr.io\u002Fgoogle-samples\u002Fnode-hello:1.0\n      securityContext:\n        runAsUser: 4000 # \u003C-- This is the pod user ID\n```\n\nAs a Kubernetes cluster administrator, you can configure a hardened default using the [`Restricted` level](https:\u002F\u002Fkubernetes.io\u002Fdocs\u002Fconcepts\u002Fsecurity\u002Fpod-security-standards\u002F#restricted) with built-in [Pod Security admission controller](https:\u002F\u002Fkubernetes.io\u002Fdocs\u002Fconcepts\u002Fsecurity\u002Fpod-security-admission\u002F), if greater customization is desired consider using [Admission Webhooks](https:\u002F\u002Fkubernetes.io\u002Fdocs\u002Freference\u002Faccess-authn-authz\u002Fextensible-admission-controllers\u002F#what-are-admission-webhooks) or a [third party alternative](https:\u002F\u002Fkubernetes.io\u002Fdocs\u002Fconcepts\u002Fsecurity\u002Fpod-security-standards\u002F#alternatives).\n\n### RULE \\#3 - Limit capabilities (Grant only specific capabilities, needed by a container)\n\n[Linux kernel capabilities](http:\u002F\u002Fman7.org\u002Flinux\u002Fman-pages\u002Fman7\u002Fcapabilities.7.html) are a set of privileges that can be used by privileged. Docker, by default, runs with only a subset of capabilities.\nYou can change it and drop some capabilities (using `--cap-drop`) to harden your docker containers, or add some capabilities (using `--cap-add`) if needed.\nRemember not to run containers with the `--privileged` flag - this will add ALL Linux kernel capabilities to the container.\n\nThe most secure setup is to drop all capabilities `--cap-drop all` and then add only required ones. For example:\n\n```bash\ndocker run --cap-drop all --cap-add CHOWN alpine\n```\n\n**And remember: Do not run containers with the _--privileged_ flag!!!**\n\nIn Kubernetes this can be configured in [Security Context](https:\u002F\u002Fkubernetes.io\u002Fdocs\u002Ftasks\u002Fconfigure-pod-container\u002Fsecurity-context\u002F) using `capabilities` field e.g:\n\n```yaml\napiVersion: v1\nkind: Pod\nmetadata:\n  name: example\nspec:\n  containers:\n    - name: example\n      image: gcr.io\u002Fgoogle-samples\u002Fnode-hello:1.0\n      securityContext:\n        capabilities:\n          drop:\n            - ALL\n          add: [\"CHOWN\"]\n```\n\nAs a Kubernetes cluster administrator, you can configure a hardened default using the [`Restricted` level](https:\u002F\u002Fkubernetes.io\u002Fdocs\u002Fconcepts\u002Fsecurity\u002Fpod-security-standards\u002F#restricted) with built-in [Pod Security admission controller](https:\u002F\u002Fkubernetes.io\u002Fdocs\u002Fconcepts\u002Fsecurity\u002Fpod-security-admission\u002F), if greater customization is desired consider using [Admission Webhooks](https:\u002F\u002Fkubernetes.io\u002Fdocs\u002Freference\u002Faccess-authn-authz\u002Fextensible-admission-controllers\u002F#what-are-admission-webhooks) or a [third party alternative](https:\u002F\u002Fkubernetes.io\u002Fdocs\u002Fconcepts\u002Fsecurity\u002Fpod-security-standards\u002F#alternatives).\n\n### RULE \\#4 - Prevent in-container privilege escalation\n\nAlways run your docker images with `--security-opt=no-new-privileges` in order to prevent privilege escalation. This will prevent the container from gaining new privileges via `setuid` or `setgid` binaries.\n\nIn Kubernetes, this can be configured in [Security Context](https:\u002F\u002Fkubernetes.io\u002Fdocs\u002Ftasks\u002Fconfigure-pod-container\u002Fsecurity-context\u002F) using `allowPrivilegeEscalation` field e.g.:\n\n```yaml\napiVersion: v1\nkind: Pod\nmetadata:\n  name: example\nspec:\n  containers:\n    - name: example\n      image: gcr.io\u002Fgoogle-samples\u002Fnode-hello:1.0\n      securityContext:\n        allowPrivilegeEscalation: false\n```\n\nAs a Kubernetes cluster administrator, you can configure a hardened default using the [`Restricted` level](https:\u002F\u002Fkubernetes.io\u002Fdocs\u002Fconcepts\u002Fsecurity\u002Fpod-security-standards\u002F#restricted) with built-in [Pod Security admission controller](https:\u002F\u002Fkubernetes.io\u002Fdocs\u002Fconcepts\u002Fsecurity\u002Fpod-security-admission\u002F), if greater customization is desired consider using [Admission Webhooks](https:\u002F\u002Fkubernetes.io\u002Fdocs\u002Freference\u002Faccess-authn-authz\u002Fextensible-admission-controllers\u002F#what-are-admission-webhooks) or a [third party alternative](https:\u002F\u002Fkubernetes.io\u002Fdocs\u002Fconcepts\u002Fsecurity\u002Fpod-security-standards\u002F#alternatives).\n\n### RULE \\#5 - Be mindful of Inter-Container Connectivity\n\nInter-Container Connectivity (icc) is enabled by default, allowing all containers to communicate with each other through the [`docker0` bridged network](https:\u002F\u002Fdocs.docker.com\u002Fnetwork\u002Fdrivers\u002Fbridge\u002F). Instead of using the `--icc=false` flag with the Docker daemon, which completely disables inter-container communication, consider defining specific network configurations. This can be achieved by creating custom Docker networks and specifying which containers should be attached to them. This method provides more granular control over container communication.\n\nFor detailed guidance on configuring Docker networks for container communication, refer to the [Docker Documentation](https:\u002F\u002Fdocs.docker.com\u002Fnetwork\u002F#communication-between-containers).\n\nIn Kubernetes environments, [Network Policies](https:\u002F\u002Fkubernetes.io\u002Fdocs\u002Fconcepts\u002Fservices-networking\u002Fnetwork-policies\u002F) can be used to define rules that regulate pod interactions within the cluster. These policies provide a robust framework to control how pods communicate with each other and with other network endpoints. Additionally, [Network Policy Editor](https:\u002F\u002Fnetworkpolicy.io\u002F) simplifies the creation and management of network policies, making it more accessible to define complex networking rules through a user-friendly interface.\n\n### RULE \\#5a - Be careful when mapping container ports to the host with firewalls like UFW\n\n[UFW (Uncomplicated Firewall)](https:\u002F\u002Fubuntu.com\u002Fserver\u002Fdocs\u002Fhow-to\u002Fsecurity\u002Ffirewalls\u002F#ufw-uncomplicated-firewall) is a popular host-based firewall for Linux. A common misconception is that firewall rules protect all inbound traffic — including traffic destined for Docker containers. However, **Docker manages its own `iptables` and `nftables` rules directly and bypasses UFW entirely**. Note that other tools that use `iptables` or `nftables` can also have conflicts similar to UFW. If you are using other firewall tools, you should check if they are working correctly.\n\nWhen you publish a port with `-p 8000:8000`, Docker inserts `iptables` rules that open that port to **all interfaces and all source addresses**, and these rules are typically accepted before explicit firewall `DENY` rules are applied. As a result, traffic may be allowed through regardless of any `DENY` rules you have set, which can unintentionally expose container services to the public internet.\n\n#### Recommended Mitigations\n\n**Option 1 — Bind published ports to localhost only:**\n\nBind the host side of the port mapping to `127.0.0.1` so the service is only reachable locally, not from external networks:\n\n```bash\n# Vulnerable: exposes port on all interfaces\ndocker run -p 8000:8000 myimage\n\n# Safe: binds only to localhost\ndocker run -p 127.0.0.1:8000:8000 myimage\n```\n\nIn a Docker Compose file:\n\n```yaml\nservices:\n  web:\n    image: myimage\n    ports:\n      - \"127.0.0.1:8000:8000\"  # safe — localhost only\n```\n\n**Option 2 — Use `ufw-docker` (or equivalent) to enforce firewall rules over Docker networks:**\n\nFor UFW specifically, the [ufw-docker](https:\u002F\u002Fgithub.com\u002Fchaifeng\u002Fufw-docker) project provides a script and supplemental `iptables` rules that patch Docker's networking to respect UFW policies, allowing you to use standard UFW commands to control traffic to containers:\n\n```bash\n# Install ufw-docker integration rules\nsudo ufw-docker install\n\n# Allow external access to a specific container port\nsudo ufw-docker allow mycontainer 8000\u002Ftcp\n```\n\nRefer to the [Docker and iptables documentation](https:\u002F\u002Fdocs.docker.com\u002Fengine\u002Fnetwork\u002Fpacket-filtering-firewalls\u002F) for a deeper explanation of how Docker interacts with the host firewall.\n\n### RULE \\#6 - Use Linux Security Module (seccomp, AppArmor, or SELinux) for Runtime Security\n\n**First of all, do not disable default security profile!** Always start with Docker’s or your host’s default profile as a baseline.\n\n**Security Profile Recommendations:**\n\n- **Seccomp**: Restrict syscalls to the minimum required for your container. Use Docker’s default seccomp profile as a starting point and customize per workload. [Docker Seccomp](https:\u002F\u002Fdocs.docker.com\u002Fengine\u002Fsecurity\u002Fseccomp\u002F)\n\n- **AppArmor**: Apply per-container AppArmor profiles to enforce mandatory access controls. [Docker AppArmor](https:\u002F\u002Fdocs.docker.com\u002Fengine\u002Fsecurity\u002Fapparmor\u002F)\n\n- **SELinux**: Enable SELinux on the host and ensure containers are labeled properly. Enforce SELinux policies to prevent unauthorized access to host resources. [SELinux Guide for Docker](https:\u002F\u002Fdocs.docker.com\u002Fengine\u002Fsecurity\u002F)\n\n**Runtime Security Improvements:**\n\n- **Behavioral Monitoring**: Use tools like [Falco](https:\u002F\u002Ffalco.org\u002F), [Tetragon](https:\u002F\u002Ftetragon.io\u002F), or [Cilium eBPF](https:\u002F\u002Fcilium.io\u002F) to detect unexpected or malicious container activity. Examples: Unexpected exec calls, privilege escalation attempts, unusual network connections.  \n\n- **Anomaly Detection**: Continuously monitor container processes, filesystem changes, and network activity to identify abnormal patterns in real time.  \n\n- **Kubernetes Security Context**: Configure pods or containers with seccomp and AppArmor profiles in Kubernetes. [Configure a Security Context for a Pod or Container](https:\u002F\u002Fkubernetes.io\u002Fdocs\u002Ftutorials\u002Fsecurity\u002Fseccomp\u002F)\n\n### RULE \\#7 - Limit resources (memory, CPU, file descriptors, processes, restarts)\n\nThe best way to avoid DoS attacks is by limiting resources. You can limit [memory](https:\u002F\u002Fdocs.docker.com\u002Fconfig\u002Fcontainers\u002Fresource_constraints\u002F#memory), [CPU](https:\u002F\u002Fdocs.docker.com\u002Fconfig\u002Fcontainers\u002Fresource_constraints\u002F#cpu), maximum number of restarts (`--restart=on-failure:\u003Cnumber_of_restarts>`), maximum number of file descriptors (`--ulimit nofile=\u003Cnumber>`) and maximum number of processes (`--ulimit nproc=\u003Cnumber>`).\n\n[Check documentation for more details about ulimits](https:\u002F\u002Fdocs.docker.com\u002Fengine\u002Freference\u002Fcommandline\u002Frun\u002F#set-ulimits-in-container---ulimit)\n\nYou can also do this for Kubernetes: [Assign Memory Resources to Containers and Pods](https:\u002F\u002Fkubernetes.io\u002Fdocs\u002Ftasks\u002Fconfigure-pod-container\u002Fassign-memory-resource\u002F), [Assign CPU Resources to Containers and Pods](https:\u002F\u002Fkubernetes.io\u002Fdocs\u002Ftasks\u002Fconfigure-pod-container\u002Fassign-cpu-resource\u002F) and [Assign Extended Resources to a Container](https:\u002F\u002Fkubernetes.io\u002Fdocs\u002Ftasks\u002Fconfigure-pod-container\u002Fextended-resource\u002F)\n\n### RULE \\#8 - Set filesystem and volumes to read-only\n\n**Run containers with a read-only filesystem** using `--read-only` flag. For example:\n\n```bash\ndocker run --read-only alpine sh -c 'echo \"whatever\" > \u002Ftmp'\n```\n\nIf an application inside a container has to save something temporarily, combine `--read-only` flag with `--tmpfs` like this:\n\n```bash\ndocker run --read-only --tmpfs \u002Ftmp alpine sh -c 'echo \"whatever\" > \u002Ftmp\u002Ffile'\n```\n\nThe Docker Compose `compose.yml` equivalent would be:\n\n```yaml\nversion: \"3\"\nservices:\n  alpine:\n    image: alpine\n    read_only: true\n```\n\nEquivalent in Kubernetes in [Security Context](https:\u002F\u002Fkubernetes.io\u002Fdocs\u002Ftasks\u002Fconfigure-pod-container\u002Fsecurity-context\u002F):\n\n```yaml\napiVersion: v1\nkind: Pod\nmetadata:\n  name: example\nspec:\n  containers:\n    - name: example\n      image: gcr.io\u002Fgoogle-samples\u002Fnode-hello:1.0\n      securityContext:\n        readOnlyRootFilesystem: true\n```\n\nIn addition, if the volume is mounted only for reading **mount them as a read-only**\nIt can be done by appending `:ro` to the `-v` like this:\n\n```bash\ndocker run -v volume-name:\u002Fpath\u002Fin\u002Fcontainer:ro alpine\n```\n\nOr by using `--mount` option:\n\n```bash\ndocker run --mount source=volume-name,destination=\u002Fpath\u002Fin\u002Fcontainer,readonly alpine\n```\n\n### RULE \\#9 - Integrate container scanning tools into your CI\u002FCD pipeline\n\n[CI\u002FCD pipelines](CI_CD_Security_Cheat_Sheet.md) are a crucial part of the software development lifecycle and should include various security checks such as lint checks, static code analysis, and container scanning.\n\nMany issues can be prevented by following some best practices when writing the Dockerfile. However, adding a security linter as a step in the build pipeline can go a long way in avoiding further headaches. Some issues that are commonly checked are:\n\n- Ensure a `USER` directive is specified\n- Ensure the base image version is pinned\n- Ensure the OS packages versions are pinned\n- Avoid the use of `ADD` in favor of `COPY`\n- Avoid curl bashing in `RUN` directives\n\nReferences:\n\n- [Docker Baselines on DevSec](https:\u002F\u002Fdev-sec.io\u002Fbaselines\u002Fdocker\u002F)\n- [Use the Docker command line](https:\u002F\u002Fdocs.docker.com\u002Fengine\u002Freference\u002Fcommandline\u002Fcli\u002F)\n- [Overview of Docker Compose v2 CLI](https:\u002F\u002Fdocs.docker.com\u002Fcompose\u002Freference\u002Foverview\u002F)\n- [Configuring Logging Drivers](https:\u002F\u002Fdocs.docker.com\u002Fconfig\u002Fcontainers\u002Flogging\u002Fconfigure\u002F)\n- [View logs for a container or service](https:\u002F\u002Fdocs.docker.com\u002Fconfig\u002Fcontainers\u002Flogging\u002F)\n- [Dockerfile Security Best Practices](https:\u002F\u002Fcloudberry.engineering\u002Farticle\u002Fdockerfile-security-best-practices\u002F)\n\nContainer scanning tools are especially important as part of a successful security strategy. They can detect known vulnerabilities, secrets and misconfigurations in container images and provide a report of the findings with recommendations on how to fix them. Some examples of popular container scanning tools are:\n\n- Free\n    - [Clair](https:\u002F\u002Fgithub.com\u002Fquay\u002Fclair)\n    - [Grype](https:\u002F\u002Fgithub.com\u002Fanchore\u002Fgrype)\n    - [Trivy](https:\u002F\u002Fgithub.com\u002Faquasecurity\u002Ftrivy)\n- Commercial\n    - [Snyk](https:\u002F\u002Fsnyk.io\u002F) **(open source and free option available)**\n    - [Anchore](https:\u002F\u002Fgithub.com\u002Fanchore\u002Fgrype\u002F) **(open source and free option available)**\n    - [Docker Scout](https:\u002F\u002Fwww.docker.com\u002Fproducts\u002Fdocker-scout\u002F) **(open source and free option available)**\n    - [JFrog XRay](https:\u002F\u002Fjfrog.com\u002Fxray\u002F)\n    - [Qualys](https:\u002F\u002Fwww.qualys.com\u002Fapps\u002Fcontainer-security\u002F)\n\nTo detect secrets in images:\n\n- [ggshield](https:\u002F\u002Fgithub.com\u002FGitGuardian\u002Fggshield) **(open source and free option available)**\n- [Gitleaks](https:\u002F\u002Fgithub.com\u002Fgitleaks\u002Fgitleaks) **(open source)**\n- [TruffleHog](https:\u002F\u002Fgithub.com\u002Ftrufflesecurity\u002Ftrufflehog) **(open source)**\n\nTo detect misconfigurations in Kubernetes:\n\n- [kubeaudit](https:\u002F\u002Fgithub.com\u002FShopify\u002Fkubeaudit)\n- [kubesec.io](https:\u002F\u002Fkubesec.io\u002F)\n- [kube-bench](https:\u002F\u002Fgithub.com\u002Faquasecurity\u002Fkube-bench)\n\nTo detect misconfigurations in Docker:\n\n- [inspec.io](https:\u002F\u002Fwww.inspec.io\u002Fdocs\u002Freference\u002Fresources\u002Fdocker\u002F)\n- [dev-sec.io](https:\u002F\u002Fdev-sec.io\u002Fbaselines\u002Fdocker\u002F)\n- [Docker Bench for Security](https:\u002F\u002Fgithub.com\u002Fdocker\u002Fdocker-bench-security)\n\nTo detect misconfigurations in Docker Compose files before deployment:\n\n- [DockSec](https:\u002F\u002Fgithub.com\u002FOWASP\u002FDockSec) (with `--compose`)\n- [KICS](https:\u002F\u002Fgithub.com\u002FCheckmarx\u002Fkics)\n\n### RULE \\#10 - Keep the Docker daemon logging level at `info`\n\nBy default, the Docker daemon is configured to have a base logging level of `info`. This can be verified by checking the daemon configuration file `\u002Fetc\u002Fdocker\u002Fdaemon.json` for the`log-level` key. If the key is not present, the default logging level is `info`. Additionally, if the docker daemon is started with the `--log-level` option, the value of the `log-level` key in the configuration file will be overridden. To check if the Docker daemon is running with a different log level, you can use the following command:\n\n```bash\nps aux | grep '[d]ockerd.*--log-level' | awk '{for(i=1;i\u003C=NF;i++) if ($i ~ \u002F--log-level\u002F) print $i}'\n```\n\nSetting an appropriate log level, configures the Docker daemon to log events that you would want to review later. A base log level of 'info' and above would capture all logs except the debug logs. Until and unless required, you should not run docker daemon at the 'debug' log level.\n\n### Rule \\#11 - Run Docker in rootless mode\n\n[Rootless mode](https:\u002F\u002Fdocs.docker.com\u002Fengine\u002Fsecurity\u002Frootless\u002F#how-it-works) runs the Docker daemon and containers without host-root privileges, reducing the impact of daemon or runtime compromise. It does not guarantee protection against host privilege escalation through [kernel vulnerabilities](https:\u002F\u002Fdocs.docker.com\u002Fdesktop\u002Ftroubleshoot-and-support\u002Ffaqs\u002Flinuxfaqs\u002F#why-does-docker-desktop-for-linux-run-a-vm); the shared kernel remains part of the security boundary. Unlike rootless mode, `userns-remap` leaves the daemon running with root privileges.\n\nEvaluate the [specific requirements](Attack_Surface_Analysis_Cheat_Sheet.md) and [security posture](Threat_Modeling_Cheat_Sheet.md) of your environment to determine if rootless mode is the best choice for you. For environments where security is a paramount concern and the [limitations of rootless mode](https:\u002F\u002Fdocs.docker.com\u002Fengine\u002Fsecurity\u002Frootless\u002F#known-limitations) do not interfere with operational requirements, it is a strongly recommended configuration. Alternatively consider using [Podman](#podman-as-an-alternative-to-docker) as an alternative to Docker.\n\n> Rootless mode allows running the Docker daemon and containers as a non-root user to mitigate potential vulnerabilities in the daemon and the container runtime.\n> Rootless mode does not require root privileges even during the installation of the Docker daemon, as long as the [prerequisites](https:\u002F\u002Fdocs.docker.com\u002Fengine\u002Fsecurity\u002Frootless\u002F#prerequisites) are met.\n\nRead more about rootless mode and its limitations, installation and usage instructions on [Docker documentation](https:\u002F\u002Fdocs.docker.com\u002Fengine\u002Fsecurity\u002Frootless\u002F) page.\n\n### RULE \\#12 - Utilize Docker Secrets for Sensitive Data Management\n\nDocker Secrets provide a secure way to store and manage sensitive data such as passwords, tokens, and SSH keys. Using Docker Secrets helps in avoiding the exposure of sensitive data in container images or in runtime commands.\n\n```bash\ndocker secret create my_secret \u002Fpath\u002Fto\u002Fsuper-secret-data.txt\ndocker service create --name web --secret my_secret nginx:latest\n```\n\nFor local Docker Compose, [file-backed secrets are bind mounts](https:\u002F\u002Fdocs.docker.com\u002Fcompose\u002Fhow-tos\u002Fuse-secrets\u002F#use-secrets). Protect the source files on the host with appropriate access permissions and storage encryption; declaring a Compose secret does not encrypt these files. This differs from [Swarm-managed secrets](https:\u002F\u002Fdocs.docker.com\u002Fengine\u002Fswarm\u002Fsecrets\u002F#how-docker-manages-secrets), which are distributed over mutual TLS and stored in an encrypted Raft log:\n\n```yaml\nversion: \"3.8\"\nsecrets:\n  my_secret:\n    file: .\u002Fsuper-secret-data.txt\nservices:\n  web:\n    image: nginx:latest\n    secrets:\n      - my_secret\n```\n\nWhile Docker Secrets generally provide a secure way to manage sensitive data in Docker environments, this approach is not recommended for Kubernetes, where secrets are stored in plaintext by default. In Kubernetes, consider using additional security measures such as etcd encryption, or third-party tools. Refer to the [Secrets Management Cheat Sheet](Secrets_Management_Cheat_Sheet.md) and [Kubernetes Security Cheat Sheet](Kubernetes_Security_Cheat_Sheet.md) for more information.\n\n### RULE \\#13 - Enhance Supply Chain Security\n\nBuilding on the principles in [Rule \\#9](#rule-9---integrate-container-scanning-tools-into-your-cicd-pipeline), enhancing supply chain security involves implementing additional measures to secure the entire lifecycle of container images from creation to deployment. Some of the key practices include:\n\n- [Image Provenance](https:\u002F\u002Fslsa.dev\u002Fspec\u002Fv1.0\u002Fprovenance): Document the origin and history of container images to ensure traceability and integrity.\n- [SBOM Generation](https:\u002F\u002Fcyclonedx.org\u002Fguides\u002FCycloneDX%20One%20Pager.pdf): Create a Software Bill of Materials (SBOM) for each image, detailing all components, libraries, and dependencies for transparency and vulnerability management.\n- [Image Signing](https:\u002F\u002Fgithub.com\u002Fnotaryproject\u002Fnotary): Digitally sign images to verify their integrity and authenticity, establishing trust in their security.\n- [Trusted Registry](https:\u002F\u002Fsnyk.io\u002Flearn\u002Fcontainer-security\u002Fcontainer-registry-security\u002F): Store the documented, signed images with their SBOMs in a secure registry that enforces strict [access controls](Access_Control_Cheat_Sheet.md) and supports metadata management.\n- [Secure Deployment](https:\u002F\u002Fwww.openpolicyagent.org\u002Fdocs\u002Flatest\u002F#overview): Implement secure deployment polices, such as image validation, runtime security, and continuous monitoring, to ensure the security of the deployed images.\n\n## Podman as an alternative to Docker\n\n[Podman](https:\u002F\u002Fpodman.io\u002F) is an OCI-compliant, open-source container management tool developed by [Red Hat](https:\u002F\u002Fwww.redhat.com\u002Fen) that provides a Docker-compatible command-line interface and a desktop application for managing containers. It is designed to be a more secure and lightweight alternative to Docker, especially for environments where secure defaults are preferred. Some of the security benefits of Podman include:\n\n1. Daemonless Architecture: Unlike Docker, which requires a central daemon (dockerd) to create, run, and manage containers, Podman directly employs the fork-exec model. When a user requests to start a container, Podman forks from the current process, then the child process execs into the container's runtime.\n2. Rootless Containers: The fork-exec model facilitates Podman's ability to run containers without requiring root privileges. When a non-root user initiates a container start, Podman forks and execs under the user's permissions.\n3. SELinux Integration: Podman is built to work with SELinux, which provides an additional layer of security by enforcing mandatory access controls on containers and their interactions with the host system.\n\n## References\n\n- [Docker Engine Security](https:\u002F\u002Fdocs.docker.com\u002Fengine\u002Fsecurity\u002F)\n- [Docker Build Attestations](https:\u002F\u002Fdocs.docker.com\u002Fbuild\u002Fmetadata\u002Fattestations\u002F)\n",{},"main","5d0a87185c0e172c3901e2a6e5916b6d544b8b94","skills\u002Fdocker-security-cheat-sheet","https:\u002F\u002Fgithub.com\u002FJunMystery\u002FAgent-Guidance","https:\u002F\u002Fgithub.com\u002FJunMystery","AI is the typist, I am the architect. Building efficient, secure, and user-centric products through disciplined AI prompt engineering.","2026-11-13 17:41:25",{"source":7,"skillName":5,"commands":30,"prompt":40,"zipAvailable":41},[31,34,37],{"tool":32,"command":33},"npx","npx skills add JunMystery\u002FAgent-Guidance --skill docker-security-cheat-sheet",{"tool":35,"command":36},"bunx","bunx skills add JunMystery\u002FAgent-Guidance --skill docker-security-cheat-sheet",{"tool":38,"command":39},"pnpm","pnpm dlx skills add JunMystery\u002FAgent-Guidance --skill docker-security-cheat-sheet","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002FJunMystery\u002FAgent-Guidance\u002Fblob\u002Fmain\u002Fskills\u002Fdocker-security-cheat-sheet\u002FSKILL.md",true,[],[44,50,56,62,68,74],{"skillNo":45,"name":46,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":7,"ownerLogin":8,"ownerAvatarUrl":9,"ownerAccountNo":10,"ownerDisplayName":11,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":47,"categories":48,"keywords":49,"publishedAt":18},"01M79QR1E309VJ6CTQKB32AWWA","zero-trust-architecture-cheat-sheet","https:\u002F\u002Fgithub.com\u002FJunMystery\u002FAgent-Guidance\u002Fblob\u002Fmain\u002Fskills\u002Fzero-trust-architecture-cheat-sheet\u002FSKILL.md",[],[],{"skillNo":51,"name":52,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":7,"ownerLogin":8,"ownerAvatarUrl":9,"ownerAccountNo":10,"ownerDisplayName":11,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":53,"categories":54,"keywords":55,"publishedAt":18},"01M79QQV7GHYR02DYGN41S23WN","xss-filter-evasion-cheat-sheet","https:\u002F\u002Fgithub.com\u002FJunMystery\u002FAgent-Guidance\u002Fblob\u002Fmain\u002Fskills\u002Fxss-filter-evasion-cheat-sheet\u002FSKILL.md",[],[],{"skillNo":57,"name":58,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":7,"ownerLogin":8,"ownerAvatarUrl":9,"ownerAccountNo":10,"ownerDisplayName":11,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":59,"categories":60,"keywords":61,"publishedAt":18},"01M79QQNSN7YB8XB61FFSCS3WH","xs-leaks-cheat-sheet","https:\u002F\u002Fgithub.com\u002FJunMystery\u002FAgent-Guidance\u002Fblob\u002Fmain\u002Fskills\u002Fxs-leaks-cheat-sheet\u002FSKILL.md",[],[],{"skillNo":63,"name":64,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":7,"ownerLogin":8,"ownerAvatarUrl":9,"ownerAccountNo":10,"ownerDisplayName":11,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":65,"categories":66,"keywords":67,"publishedAt":18},"01M79QQHZZJKFDY9132G5A65C2","xpath-injection-prevention-cheat-sheet","https:\u002F\u002Fgithub.com\u002FJunMystery\u002FAgent-Guidance\u002Fblob\u002Fmain\u002Fskills\u002Fxpath-injection-prevention-cheat-sheet\u002FSKILL.md",[],[],{"skillNo":69,"name":70,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":7,"ownerLogin":8,"ownerAvatarUrl":9,"ownerAccountNo":10,"ownerDisplayName":11,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":71,"categories":72,"keywords":73,"publishedAt":18},"01M79QQB9ZSD3DJG8658EHQXR1","xml-security-cheat-sheet","https:\u002F\u002Fgithub.com\u002FJunMystery\u002FAgent-Guidance\u002Fblob\u002Fmain\u002Fskills\u002Fxml-security-cheat-sheet\u002FSKILL.md",[],[],{"skillNo":75,"name":76,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":7,"ownerLogin":8,"ownerAvatarUrl":9,"ownerAccountNo":10,"ownerDisplayName":11,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":77,"categories":78,"keywords":79,"publishedAt":18},"01M79QQ60WKV7PFMXWT9CW8PM6","xml-external-entity-prevention-cheat-sheet","https:\u002F\u002Fgithub.com\u002FJunMystery\u002FAgent-Guidance\u002Fblob\u002Fmain\u002Fskills\u002Fxml-external-entity-prevention-cheat-sheet\u002FSKILL.md",[],[]]