Get a Pentest and security assessment of your IT network.

Cyber Security

Docker Image Security Risks

TL;DR

Running Docker images from untrusted sources can be risky. This guide explains common attack vectors and how to protect your system.

Understanding the Risks

Untrusted Docker images are a potential gateway for attackers. They can contain malicious code that compromises your host machine or network. Here’s what you need to know:

1. Image Source & Verification

  1. Only use trusted registries: Prefer official repositories like Docker Hub (but even there, be cautious) and verified publishers.
  2. Check image tags: Understand the tag’s meaning. Tags like latest are often mutable and less reliable than specific version numbers.
  3. Verify publisher signatures: If available, verify the image’s signature to ensure it hasn’t been tampered with. Docker Content Trust (DCT) can help with this.
    docker trust inspect :

2. Container Privileges

  1. Run containers as non-root: Avoid running containers with root privileges whenever possible. Use the USER instruction in your Dockerfile or the --user flag when running.
    docker run --user : :
  2. Limit capabilities: Drop unnecessary Linux capabilities. Capabilities grant containers specific privileges; remove those not required.
    docker run --cap-drop ALL --cap-add NET_BIND_SERVICE :
  3. Avoid privileged mode: Never run containers in --privileged mode unless absolutely necessary. This gives the container almost full access to the host system.

3. Network Security

  1. Use network policies: Restrict network access for containers. Allow only necessary communication between containers and external networks. Tools like Docker’s networking features or third-party network policy engines can help.
  2. Port mapping: Carefully consider which ports you expose from the container to the host. Only expose essential ports.
    docker run -p 8080:80 :
  3. Firewall rules: Implement firewall rules on your host system to control inbound and outbound traffic to containers.

4. Filesystem Access

  1. Read-only root filesystem: Mount the container’s root filesystem as read-only to prevent modifications.
    docker run --read-only :
  2. Volume mounts: Be cautious with volume mounts. Avoid mounting sensitive host directories into containers unless absolutely necessary. If you must, ensure appropriate permissions are set.
  3. Tmpfs mounts: Use tmpfs mounts for temporary files to avoid writing data to the persistent filesystem.
    docker run --mount type=tmpfs,destination=/tmp :

5. Image Scanning

  1. Scan images for vulnerabilities: Use image scanning tools (e.g., Trivy, Clair, Snyk) to identify known security vulnerabilities in the image’s layers and dependencies.
    trivy image :
  2. Automate scans: Integrate image scanning into your CI/CD pipeline to automatically detect vulnerabilities before deploying images.

6. Resource Limits

  1. Set resource limits (CPU, memory): Limit the amount of CPU and memory a container can consume to prevent denial-of-service attacks or resource exhaustion.
    docker run --memory 512m --cpu-shares 512 :

7. Monitoring & Logging

  1. Monitor container activity: Monitor containers for suspicious behavior, such as unexpected network connections or file modifications.
  2. Centralized logging: Collect and analyze container logs to detect potential security incidents.

8. cyber security Best Practices

Regularly update Docker itself and the underlying host operating system with the latest security patches.

Related posts
Cyber Security

Zip Codes & PII: Are They Personal Data?

Cyber Security

Zero-Day Vulnerabilities: User Defence Guide

Cyber Security

Zero Knowledge Voting with Trusted Server

Cyber Security

ZeroNet: 51% Attack Risks & Mitigation