Docker Container Security - Practices to Consider
Tags: docker, container, security, practices
Published: 2023-07-13 12:18:21

Hello Engineers, In this article, I am going to share what container security is, some practices and standards for container security, why you should care about container security, some tools that can help us to make our containers less vulnerable.

Although there is nothing like fully secured everything in I.T industry still engineers or security engineers are required to make things less vulnerable so that your app won't get hacked or some bad guy not try to access important information (that could be leaked from containers) and also because that's what they are paid for, right.  

So before moving forward, we will be looking at a bit of docker architecture as we are learning security in the docker context.

**[Docker](https://www.docker.com/)**, the most popular open-source containerization tool also standard for most of the platforms of the container launched in 2013 by Docker Inc.  Engineers can easily create, deploy, and run applications in a self-contained environment called a container.  It quickly gained popularity among developers and system administrators because it simplified the process of deploying applications across different environments, such as development, testing, and production

Docker has a full-fledged  Architecture that contains some specific components that are:

- Docker Client: This is a command-line tool that allows users to interact with the Docker platform.
- Docker Daemon: This is the background process that runs on the host machine and manages the containers.
- Docker Images: An image is a lightweight, standalone, executable package that includes everything needed to run the software, including the code, libraries, and dependencies.
- Docker Registry: This is a repository that stores Docker images.
  

The above details of Docker are essential to understand how docker works internally. But this article mostly covers related to security, so I won't go into further details of how docker actually works.


## Container Security

If we talk about container security, whether we work on Docker, LXD, RKT, Apache Mesos or any other tools your organization uses, the principles will be the same for overall container security. 

**_Container security_** refers to the practices and technologies used to protect containerized applications. It can be any kind of application either micro-services, SPAs (Single page applications), Utilities or API etc. Those practices are used to protect containers from unauthorized data access, malicious attacks, and other security threats.

[Containers](https://www.docker.com/resources/what-container/) are a lightweight and portable way to package and deploy applications, but they also introduce new security risks that need to be addressed as containers share the host kernel and can be vulnerable to attacks if not properly secured.

<br />

---

<br />

## Container Security Considerations


- <u>**Host/Kernel Security**</u>:
Containers share the host kernels, which means any vulnerabilities in kernel or host can affect all the containers running on that host. It is important to keep the host system secure by regularly updating security patches, using anti-malware software, implementing other host security measures, Run container security tools like [docker-bench-security](https://github.com/docker/docker-bench-security).

<br />

- <u>**Access Control**</u>:
Containers should be run with the least amount of privileges necessary to perform their tasks, and access to containers and their associated resources. Always run it as **non-root user**. It is best to create a new user to perform and access docker resources. Running your containers on rootless mode will verify that your application environment is safe.

<br />

- <u>**Container Monitoring**</u>:
Monitoring is important for container activity and log events to detect potential vulnerabilities and incidents, and to have processes in place for responding to security incidents and implementing remediation measures.  Use tools like Docker Logging and Use Docker's health check feature to periodically check the status of containerized applications.

<br />

- <u>**Image Vulnerability Scanning**</u>:
Containers are created from images, which can contain software vulnerabilities, malware, or other security risks. It is important to use trusted and verified images, scan images for vulnerabilities, and follow best practices for image security.
<u>Periodic scanning</u> allows you to keep your images updated and audit critical directories and files. Tools like [Anchore](https://anchore.com/blog/docker-image-security-in-5-minutes-or-less/), [Clair](https://github.com/quay/clair), or [Trivy](https://aquasecurity.github.io/trivy/v0.43/) can scan container images and provide vulnerability reports.

<br />

- <u>**Docker Security Policies**</u>:
Docker environment allows use to setup our security policies in order to make our containers secure. Only use Docker images from trusted and verified sources. Create policies to restrict image pulls to approved Docker registries and repositories. Enforce Container strict isolation to prevent malicious attacks. We can use Use container runtime options like `--privileged=false` and `--cap-drop` to limit container capabilities. Create policies to implement network segmentation and firewall rules to control container communication. We can use Use Docker's built-in network features or there are some other tools like **<u>[cillium](https://cilium.io/)</u>** or **<u>[docker-bench](https://github.com/docker/docker-bench-security)</u>** to isolate containers and define ingress/egress rules.
<br /> 

## Conclusion
Container security is a critical consideration when using containerization technologies like Docker and Kubernetes. By implementing best practices for container security, organizations can reduce the risk of security incidents and protect their applications and data from unauthorized access and other security threats.

<br />

If you like my article, please like and share feedback and let me know in comments. And don't forget to follow me on [Linkedin](https://www.linkedin.com/in/mquanit/), [Github](https://github.com/Mohammad-Quanit), [Twitter](https://twitter.com/mquanit).

Peace ✌🏻