VOOZH about

URL: https://thenewstack.io/anchore-scan-your-container-images-for-vulnerabilities-from-the-command-line/

⇱ Anchore: Scan Your Container Images for Vulnerabilities from the Command Line - The New Stack


TNS
SUBSCRIBE
Join our community of software engineering leaders and aspirational developers. Always stay in-the-know by getting the most important news and exclusive content delivered fresh to your inbox to learn more about at-scale software development.
REQUIRED
It seems that you've previously unsubscribed from our newsletter in the past. Click the button below to open the re-subscribe form in a new tab. When you're done, simply close that tab and continue with this form to complete your subscription.
The New Stack does not sell your information or share it with unaffiliated third parties. By continuing, you agree to our Terms of Use and Privacy Policy.
Welcome and thank you for joining The New Stack community!
Please answer a few simple questions to help us deliver the news and resources you are interested in.
REQUIRED
REQUIRED
REQUIRED
REQUIRED
REQUIRED
Great to meet you!
Tell us a bit about your job so we can cover the topics you find most relevant.
REQUIRED
REQUIRED
REQUIRED
REQUIRED
REQUIRED
Welcome!

We’re so glad you’re here. You can expect all the best TNS content to arrive Monday through Friday to keep you on top of the news and at the top of your game.

What’s next?

Check your inbox for a confirmation email where you can adjust your preferences and even join additional groups.

Follow TNS on your favorite social media networks.

Become a TNS follower on LinkedIn.

Check out the latest featured and trending stories while you wait for your first TNS newsletter.

PREV
1 of 2
NEXT
VOXPOP
As a JavaScript developer, what non-React tools do you use most often?
Angular
0%
Astro
0%
Svelte
0%
Vue.js
0%
Other
0%
I only use React
0%
I don't use JavaScript
0%
Thanks for your opinion! Subscribe below to get the final results, published exclusively in our TNS Update newsletter:
NEW! Try Stackie AI
From clobbered drafts to real-time sync
Apr 14th 2026 10:00am, by David Moore
TypeScript 6.0 RC arrives as a bridge to a faster future
Mar 14th 2026 9:00am, by Darryl K. Taft
Mastra empowers web devs to build AI agents in TypeScript
Jan 28th 2026 11:00am, by Loraine Lawson
2021-06-04 11:40:25
Anchore: Scan Your Container Images for Vulnerabilities from the Command Line
tutorial,
Containers / DevOps / Security

Anchore: Scan Your Container Images for Vulnerabilities from the Command Line

Anchore Engine, a open-source software for inspection, analysis, and certification of container images. The Anchore CLI provides a developer interface for these capabilities. This piece of command-line magic can pull down images from the official Docker registry (or other registries), store them in a local library, and then run vulnerability scans, policy evaluations, and even list system packages found in the image.
Jun 4th, 2021 11:40am by Jack Wallen
👁 Featued image for: Anchore: Scan Your Container Images for Vulnerabilities from the Command Line
Feature Image par Gerd Altmann de Pixabay

You develop for a Kubernetes cluster. Or maybe you deploy single container microservices to your cloud-hosted platform. Either way, your work depends on having images that are as free from vulnerabilities as possible. No matter if you develop your own images from the ground up, or if you use pre-rolled images, you need to know where they stand with regards to security.

One way to take care of that is using the Anchore Engine, an open source software for inspection, analysis, and certification of container images. The Anchore CLI provides a developer interface for these capabilities. This piece of command-line magic can pull down images from the official Docker registry (or other registries), store them in a local library, and then run vulnerability scans, policy evaluations, and even list system packages found in the image. In other words, it can ensure the images you depend on are good to go.

But Anchore CLI isn’t exactly the most writ large tool in the developer toolkit. Not only is it yet another container adjacent tool with less-than-ideal installation documentation, but its usage also isn’t exactly obvious. I’m going to clear that up for you, such that you can get Anchore CLI in play with your daily container development workflow.

To make this work, you’ll need a running instance of Linux that supports Docker and a user with sudo privileges. I’ll be demonstrating with Ubuntu Server 20.04, but the process is similar on most Linux distributions (so long as you modify the installation commands to match your distribution’s package manager).

With that said, let’s get Anchore CLI up and running.

Installing Anchore CLI

The first thing we must do is install Anchore CLI. Before we do that, we’ll make sure we have Docker installed. For that, log into your Ubuntu server and install Docker with the command:

sudo apt-get install docker.io -y

Once installed, add your user to the docker group with the command:

sudo usermod -aG docker $USER

Log out and log back in, so the changes take effect.

Once Docker is installed, we need to install PIP, which is done with the command:

sudo apt-get install python3-pip -y

With the Python package manager added to the system, you can then install Anchore CLI with the command:

pip install anchorecli

When the above command completes, you’ll find the anchore-cli command isn’t available to run. Why? Because Pip installs the executable in ~/.local/bin, which is not a part of your user path. To fix that you need to add the directory to your path with the command:

export PATH="$HOME/.local/bin/:$PATH"

At this point, if you issue the command anchore-cli, you’ll find it’s unable to connect to the Anchore Engine. That’s because we have to add that to the system. Fortunately, the easiest path to get this subsystem up and running is to deploy it as a container. For that, we’re going to need to add Docker Compose into the mix. This can be done with the following two commands:

sudo curl -L "https://github.com/docker/compose/releases/download/1.23.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

sudo chmod +x /usr/local/bin/docker-compose

Next, download the Anchore Engine YAML file with the command:

curl https://engine.anchore.io/docs/quickstart/docker-compose.yaml > docker-compose.yaml

With the YAML stored, deploy the engine with the command:

docker-compose up -d

After Anchore Engine has deployed, you need to give it a few minutes to come up. While it’s working, let’s export some variables (so you don’t have to always add them into the Anchore CLI commands). We’re going to set the URL, user, and password variables. The default credentials for Anchore Engine are admin/foobar.

If you want, you can change the admin password (before you issue the docker-compose up -d command). To do that, open the docker-compose.yaml file you downloaded a moment ago and look for the line:

- ANCHORE_ADMIN_PASSWORD=foobar

Change foobar to whatever password you like. Save and close the file. If you’ve already deployed the Anchore Engine contain, before changing the password, issue the command:

docker-compose down

When the container shuts down, change the password and then re-deploy the container.

To set the environment variables, issue the following three commands:

ANCHORE_CLI_URL=http://SERVER:8228/v1

ANCHORE_CLI_USER=admin

ANCHORE_CLI_PASS=PASSWORD

Where SERVER is the IP address of your server and PASSWORD is what you set in the YAML file (NOTE: If you didn’t change the password, make sure to use foobar).

Using Anchore CLI

You’re now ready to make use of Anchore CLI. First, let’s download an image, and then we’ll scan it. We’ll download the official openjdk:8-jre-alpine image with the command:

anchore-cli --u admin --p foobar image add docker.io/library/openjdk:8-jre-alpine

After the image is downloaded, Anchore CLI will begin the process of analyzing the image. This will take some time. If you issue the command:

anchore-cli --u admin --p foobar image list

You will see that the openjdk-8-jre-alpine image is still in the process of being analyzed (Figure 1).

👁 Image

Figure 1: The analysis of the openjdk-8-jre-alpine image isn’t complete.

If you receive the error “Unauthorized,” it’s because Anchore CLI isn’t recognizing the variables you set. I’ve found this to be far too common than not. To get around that, you must issue the command, including the authorization credentials like so:

anchore-cli --u admin --p foobar image list

Once the image has moved from analyzing to analyzed (you’ll need to keep issuing the image list command to find out), you can then perform a vulnerability scan with the command:

anchore-cli --u admin --p foobar image vuln docker.io/library/openjdk:8-jre-alpine all

The above command will list out all of the known vulnerabilities (Figure 2) associated with the image (if there are any).

👁 Image

Figure 2: A few CVEs listed as High my keep you from using this image.

If you find an image contains too many unacceptable vulnerabilities, your best choice would be to avoid that image and find another to use for development purposes.

To run a policy check, the command would be:

anchore-cli --u admin --p foobar evaluate check docker.io/library/debian:latest --detail

From that command you should see output like:

Image Digest: sha256:3e24baa60967d085b95a45129f82af4eb9d1e33aff9559173542ebb15c5d9cb5
Full Tag: docker.io/library/debian:latest
Image ID: 4a7a1f4017349067a21bd2de060dcf8b41e49fabf61b0dc3cf86a87e1f6dba9d
Status: pass
Last Eval: 2021-05-28T14:14:21Z
Policy ID: 2c53a13c-1765-11e8-82ef-23527761d060
Final Action: warn
Final Action Reason: policy_evaluation
Gate Trigger Detail Status
dockerfile instruction Dockerfile directive 'HEALTHCHECK' not found, matching condition 'not_exists' check warn
vulnerabilities package MEDIUM Vulnerability found in os package type (dpkg) - libgnutls30 (CVE-2011-3389 - https://security-tracker.debian.org/tracker/CVE-2011-3389) warn

You can even subscribe to receive notifications when new CVEs are added to an update with the command:

anchore-cli --u admin --p foobar subscription activate vuln_update docker.io/library/debian:latest

And that’s all there is to installing and using Anchore CLI, to ensure you’re using container images that are safe from vulnerabilities. Use this tool wisely (and often) and it will serve you well.

TRENDING STORIES
Jack Wallen is what happens when a Gen Xer mind-melds with present-day snark. Jack is a seeker of truth and a writer of words with a quantum mechanical pencil and a disjointed beat of sound and soul. Although he resides...
Read more from Jack Wallen
SHARE THIS STORY
TRENDING STORIES
TNS owner Insight Partners is an investor in: Docker.
SHARE THIS STORY
TRENDING STORIES
TNS DAILY NEWSLETTER Receive a free roundup of the most recent TNS articles in your inbox each day.
The New Stack does not sell your information or share it with unaffiliated third parties. By continuing, you agree to our Terms of Use and Privacy Policy.