DEV Community

Liran Tal for Snyk

Posted on

Don't let security vulnerabilities crawl into your Node.js Docker images

When we choose a base image for our Docker container, we indirectly take upon ourselves the risk of all the security concerns that the base image is bundled with.

This can be poorly configured defaults that don’t contribute to the security of the operating system, as well as system libraries that are bundled with the base image we chose.

Based on scans performed by Snyk users, it was found that 44% of Docker image scans had known vulnerabilities, and for which there were newer and more secure base images available.

A good first step is to make use of as minimal a base image as is possible while still being able to run your application without issues.

This helps reduce the attack surface by limiting exposure to vulnerabilities; on the other hand, it doesn’t run any audits on its own, nor does it protect you from future vulnerabilities that may be disclosed for the version of the base image that you are using.

Therefore, one way of protecting against vulnerabilities in open source software is to use tools such as Snyk, to add continuous scanning and monitoring of vulnerabilities that may exist across all of the Docker image layers that are in use.

In action, a snyk test for a docker image:

snyk test for security vulnerabilities in a docker image

To practice the same workflow you can use snyk to scan a Docker image for known vulnerabilities with these commands:

# fetch the image to be tested so it exists locally
$ docker pull node:10
# scan the image with snyk
$ snyk test --docker node:10 --file=path/to/Dockerfile
Enter fullscreen mode Exit fullscreen mode

Monitoring vulnerabilities as they get discovered is not any less important than scanning them to begin with.

Monitor a Docker image for known vulnerabilities so that once newly discovered vulnerabilities are found in the image, Snyk can notify and provide remediation advice:

$ snyk monitor --docker node:10
Enter fullscreen mode Exit fullscreen mode

Snyk also found that for 20% out of all Docker image scans, only a rebuild of the Docker image would be necessary in order to reduce the number of vulnerabilities.


This tip is part of a complete 10 Docker image security best practices you should adopt. Thanks for reading and to Omer Levi Hevroni who worked with me on it.

The original blog post includes a high-resolution printable PDF like the snippet you see below. Check it out

Top comments (0)