Docker Scout - Scouting The Security Seas
Published: 2024-01-09 07:10:58

Ever wondered how to navigate the travesties of security pitfalls, package integrities, and protection of our Docker images? 

While Docker has made the developer’s life easy, there is still something crucial to take care of when we are dockerising our code.

Why? Because our container images are made up of many different layers of softwares, packages, and potentially other images too. And just like any software, our images are vulnerable to potential security threats ranging from as simple as an outdated package to a major slip up in external images. 

Fortunately, Docker has released a scanning tool - **Docker Scout** - that helps us gain insights into the contents of a container image and accordingly fix them. The best part is that it can integrate with any CI pipeline we have including GitHub actions, Circle CI, GitLab, etc

## Let’s get started 🐳

You can watch the video here about Docker Scout.
{% youtube Dal3Nge32cU %}

### How to use Docker Scout with Docker CLI?

Firstly, we need to have Docker installed on our system - that means installing the CLI for it and the Docker Desktop app for our OS. 

Confirm the installation with this command - `docker –version`; if it returns a version number similar to the below image, we are good to go.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zrl7ui9369sv47v85eec.png)

And make sure to have Docker Desktop up and running as well.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pvwwitay23fmjjahq1r2.png)


Now, check using the CLI, if Docker Scout is available in the list of commands - and it should be 🤓

Type `docker scout –help` and we should get the below help information - 


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a5vfogo2mtykzfhvelhg.png)



As we can see, there are many commands available, but there are two very important commands worth noting, and which we will be using extensively -

- `docker scout quickview`
- `docker scout cves`

As you might have guessed, CVE stands for Common Vulnerabilities and Exposures, and this command helps us identify or “scout” for issues in our images. It does this by comparing with the huge database of recorded vulnerabilities and security issues stored in Docker. We can see the complete list of these CVEs by visiting[https://dso.docker.com/explore](https://dso.docker.com/explore). 


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5kqkqbvwdo19egcwki5r.png)


We can filter these CVEs by Image or Package or Vulnerability name if we are aware of them.

And as for the `quickview` command, just like the name suggests, it helps us get details about an image or package.

Let’s do a scout of the first most vulnerable image - `storm:latest` (as can be seen in the right side of the above image). Run `docker scout quickview storm`


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o7s60ztyvqxmho6qhqtl.png)


We can see that the CLI returned a nice tabular view of the details of this Docker image. There are 55 “Critical” dependencies as marked in red colour, 123 “High”, 109 “Medium”, and 24 “Low” rankings of vulnerabilities. 

But it’s more fun to actually use Docker Scout on our own existing application isn’t it? Here, I have opened a project folder within VS Code with the necessary dockerfiles - 


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2qrfdlh5mr4w61073uut.png)

So now that we have this basic setup ready, let us first build the project with Docker. 

Type the command `docker build -t image_name`

Replace `image_name` with the name of your image; here I have used the name “mern”, as it can be seen below - 


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/q4ncup7zkbhf2b23v4tk.png)

Once the command is executed, we can see that all the steps we have defined in our Dockerfile will be followed exactly as it is - it installs Node v.18 along with the required dependencies, and once this image is available, we can check for the vulnerabilities. 

First, let’s run the command `docker images` to list all the available images in our system - 


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w56fxmt3d3ng4bivtd7b.png)


Here, we have the image “mern” available since we ran it just a moment ago. And now, let’s run the command `docker scout quickview mern` on our image. 


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hz9un5ef57h1paefspgi.png)


Aaand.. Voila! There we have it. Docker Scout has detected 2 “Critical” vulnerabilities, 3 “High”, 14 “Medium”, and 89 “Low” ones. 

And now, we can run `docker scout cves mern` to exactly see which package or layer created these vulnerabilities!


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dd58w8c61owe6nkbls0m.png)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8icivovwcyyvuezijipk.png)


There we go! Now we have in-depth details about each vulnerability, sorted by package and layer according to the contents of our image. 

As you can see, the command not only gives the name of the package that has the vulnerability, but also the correct “fixed” version of the same to help us in updating to the latest stable, secure version. 

But there are also instances where many packages or images are not yet fixed even though they may have critical vulnerabilities, like so - 


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/himteggyeae9zmqto6v9.png)

In such cases, rather than getting confused by the large list of vulnerabilities, we can use a flag `--only-fixed` with the Docker Scout command to shorten the list to a more fixable list. Here’s how to do it - 


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/edw7ee8cix6qn4j88bqs.png)

This will ONLY list out the fixable vulnerabilities where a stable/fixed version of it is available. In our example, `openssh`, `mongoose`, etc all have “fixed” versions that are not vulnerable anymore so we can easily upgrade these in our project’s package manager. 


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/f8wlh9n3985qst9fmirt.png)


And here’s how I upgraded the mongoose package vulnerability easily - 


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/21d2vwdvnfg0phliw566.png)

Next, we can run the same command `docker build -t image_name_2` to build a new image of the same project, and then run `docker scout cves image_name_2 –only-fixed` and we will find that the list is considerably shorter than before! 


### How to use Docker Scout with Docker Desktop app?

Since Docker desktop app provides a very fluid GUI, it is much more visually pleasing for those who prefer to not use the CLI. Open the Docker app and we should be able to see the local Docker images listed like so - 


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/szxrl1in2zyriot700rj.png)


And once we click on the image, which is “mern” in this case, we can see the entire list of vulnerabilities presented similar to the CLI but more visual - 


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lmaab5w58ogwrscwc3bn.png)


We can even filter the list by checking the checkbox labeled “Fixable packages” and this will function in a similar way to that of the flag we used earlier - `--only-fixed`.

There is an interesting option in the Docker app which is the “Recommended Fixes” option. 


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/730zwfi5eatuo481phm3.png)



Once we click on the Recommended Fixes dropdown, we can see an option for “Recommendations for base image”. Click on that, and we will get this page where Docker recommends a fix for the base image node. As we can see, the current image node is 18, but the recommended options are 20, 21, etc. 



![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pweib4pp5cxlko2tpur5.png)

How to use this recommendation?

Well, it’s quite simple! Scroll down on that recommendation page in the app, and we will see this below line to be added in our Dockerfile. Just copy and paste it like so -


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/iezm0o1kbk7w9skipxjv.png)



![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3yjh4o3qrtr6ke1g409q.png)


And once we have updated the base image node, we can just run the command `docker build -t image new_image` and now we will see the same image listed among the local images in Docker app. 

And here’s the magic of Docker Scout - the number of vulnerabilities came down from 100+ to just 24 🤩Yes, that’s the power of Docker Scout. 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pb2zvv5hbi1wc21cb373.png)


Your Docker image is now that much more secure, powerful, and vulnerable-free compared to your previous build!

No more bumping the heads against the wall trying to track down which package is destroying your app or which version to fix; simply use Docker Scout and let the magic happen 🎉

And in case you prefer watching this in video format, I have made a detailed video on Docker Scout and its usage on my channel here - [What is Docker Scout?](https://www.youtube.com/watch?v=Dal3Nge32cU&t=125s&ab_channel=Bitfumes)

Please subscribe to my newsletter https://bitfumes.com/newsletters