> For the complete documentation index, see [llms.txt](https://docs.sonarsource.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.sonarsource.com/sonarqube-cloud/advanced-security/container-scanning.md). Agents can also search and read this documentation through its [MCP server](https://docs.sonarsource.com/~gitbook/mcp).

# Container scanning

Container scanning extends the capabilities of SonarQube Advanced Security to the analysis of container images.

Run the container scanning client CLI tool against an image to track the components of that image and see which vulnerabilities are present.

Container scanning is part of [SonarQube Advanced Security](https://docs.sonarsource.com/sonarqube-cloud/advanced-security/introduction.md), which requires a separate subscription in addition to your Team or Enterprise plan.

Container scanning analyzes containers looking for two types of risks:

* Malicious packages: whether known malicious software is present in the container
* Vulnerabilities: whether components in the container image contain known, public, vulnerabilities

License risks and license policy are not available for container images, as licensing constraints for the use of container images are different than for code projects.

## Supported base container operating systems

Vulnerability tracking is available for the same base container runtimes that are supported by [SonarQube's SBOM import](https://docs.sonarsource.com/sonarqube-cloud/advanced-security/analyzing-projects-for-dependencies-sca.md#sbom-import-requirements), notably:

* Red Hat Enterprise Linux
* Rocky Linux
* AlmaLinux
* Debian (11 and higher)
* Ubuntu
* Alpine

## Required permissions

Container scanning is enabled by default for all SonarQube Advanced Security users. The following applies at the organization level:

* **Scanning**: you need a personal access token. See [Generating personal tokens](https://docs.sonarsource.com/sonarqube-cloud/managing-your-account/managing-tokens.md#personal-tokens).
* **Viewing**: anyone in the organization can open **Container images** in the sidebar.
* **Manage container risks**: change the status and severity of dependency risks found in container images.

**Manage container risks** is granted to organization owners by default. Owners can also grant it to other users or groups. See [Managing organization permissions](https://docs.sonarsource.com/sonarqube-cloud/administering-sonarcloud/managing-organization/users-and-permissions/organization-permissions.md#setting-permissions).

## Download the scanner

The scanner is available for:

* Linux x64
* Linux arm64
* macOS x64
* macOS arm64
* Windows x64

Download the binary for your platform from [binaries.sonarsource.com](https://binaries.sonarsource.com/?prefix=CommercialDistribution/sonar-container-scanner/).

On Linux and macOS, make `sonar-container-scanner` available in your `PATH`, for example by installing the executable in `~/.local/bin`:

```shell
chmod +x sonar-container-scanner-<version>-<platform>.bin
mkdir -p ~/.local/bin
mv sonar-container-scanner-<version>-<platform>.bin ~/.local/bin/sonar-container-scanner
```

## Run the analysis

After you've downloaded the scanner, run the following command to analyze a container image:

```shell
sonar-container-scanner <IMAGE> --organization <ORGANIZATION_KEY> --token <TOKEN>
```

Pass your organization and token as environment variables, especially in CI, so the token does not appear in command history or logs:

| Environment variable            | Equivalent flag  |
| ------------------------------- | ---------------- |
| `SONAR_CONTAINER_SCANNER_ORG`   | `--organization` |
| `SONAR_CONTAINER_SCANNER_TOKEN` | `--token`        |
| `SONAR_HOST_URL`                | `--host-url`     |

```shell
export SONAR_CONTAINER_SCANNER_ORG=<ORGANIZATION_KEY>
export SONAR_CONTAINER_SCANNER_TOKEN=<TOKEN>
sonar-container-scanner alpine:3.19
```

If you set both a flag and its environment variable, the flag takes precedence.

### SonarQube Cloud instance

By default, the scanner submits the analysis to SonarQube Cloud at `https://sonarcloud.io`. If your organization is on another instance, such as the US or AU instance, set `--host-url` or `SONAR_HOST_URL`:

```shell
# US instance
sonar-container-scanner alpine:3.19 --host-url https://sonarqube.us
# AU instance
sonar-container-scanner alpine:3.19 --host-url https://sonarqube.au
```

The URL must use `https`.

### Supported image inputs

| Input                                                                                                                                                                                     | Example                                         |
| ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------- |
| Container image reference, from Docker or Podman                                                                                                                                          | `alpine:3.19`, `myregistry/app@sha256:<digest>` |
| Local `.tar` archive ([docker-archive](https://docs.docker.com/reference/cli/docker/image/save/) or [OCI layout](https://github.com/opencontainers/image-spec/blob/main/image-layout.md)) | `./my-image.tar`                                |
| Local directory containing an OCI layout                                                                                                                                                  | `./my-image-oci/`                               |

The image must already be available locally, for example after `docker build`, `docker pull`, `podman build`, or `podman pull`. The scanner does not pull missing images.

### Using Podman

When you scan an image reference, the scanner exports the image from your container engine:

* If only Podman is installed, the scanner uses it automatically.
* If both Docker and Podman are installed, the scanner uses Docker by default. To use Podman instead, pass `--container-engine podman`.

```shell
sonar-container-scanner my-app:1.4.0 --container-engine podman
```

Docker and Podman keep separate image stores, so the image must be available in the engine the scanner uses. `--container-engine` is ignored when you scan a `.tar` archive or an OCI layout directory.

### Image identity

The scanner automatically detects the image's registry, repository, and tag from the input. If it cannot identify a single image, platform, or origin, it stops with exit code `2` rather than guessing. In that case, or whenever you want to set the identity yourself, use these flags:

| Flag           | Purpose                                                      | Example          |
| -------------- | ------------------------------------------------------------ | ---------------- |
| `--registry`   | Registry of the image. Pass it together with `--repository`. | `docker.io`      |
| `--repository` | Repository of the image. Pass it together with `--registry`. | `library/alpine` |
| `--tag`        | Tag of the image                                             | `3.19`           |

The scanner does not verify that a tag you pass with `--tag` points to the scanned image. Results are recorded against the image digest, under the tag you provide.

## Failing your pipeline on risky images

Use `--fail-on` to make the scanner exit with a failing code when it finds risks at or above a given severity. Your CI pipeline can then stop vulnerable images before they ship.

```shell
sonar-container-scanner my-app:1.4.0 --fail-on medium
```

Accepted values: `none`, `info`, `low`, `medium`, `high`, `blocker`. The default is `high`. Use `none` to never fail on risk severity.

### Exit codes

| Exit code | Meaning                                                                                                                                                                |
| --------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `0`       | The scan completed and found no risks at or above the `--fail-on` severity.                                                                                            |
| `1`       | The scan completed and found at least one risk at or above the `--fail-on` severity.                                                                                   |
| `2`       | The scan could not run or could not be submitted, for example because the image was not found, its identity is ambiguous, access was denied, or a timeout was reached. |

Exit code `2` is returned even with `--fail-on none`, so a failed scan is never reported as a pass. The scanner does not retry failed requests. To add resilience in CI, retry the whole command.

### Example: scan an image after building it in CI

```shell
docker build -t my-app:${BUILD_TAG} .
sonar-container-scanner my-app:${BUILD_TAG} --fail-on medium
```

Set `SONAR_CONTAINER_SCANNER_ORG` and `SONAR_CONTAINER_SCANNER_TOKEN` as secret environment variables in your CI system.

### Speeding up CI runs with caching

The scanner includes an embedded SBOM generator ([syft](https://github.com/anchore/syft)). On the first run, it extracts this generator into a local cache, which takes a few seconds. To avoid paying that cost on every CI job, cache the scanner's cache directory between jobs.

The scanner uses the first of these locations that's set:

1. `$SONAR_CONTAINER_SCANNER_CACHE_DIR`, used as-is. Useful for a read-only `$HOME` or a locked-down CI environment.
2. `$SONAR_USER_HOME/container-scanner`
3. `$HOME/.sonar/container-scanner` (`%USERPROFILE%\.sonar\container-scanner` on Windows)

## Network configuration

If your network requires a proxy or a custom certificate authority to reach SonarQube Cloud, set these environment variables:

| Environment variable    | Description                                                                                                                                                                                                                                    |
| ----------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `SONAR_HTTPS_PROXY_URL` | Proxy URL for HTTPS requests. Credentials in the URL are sent to the proxy.                                                                                                                                                                    |
| `SONAR_NO_PROXY`        | Hosts that bypass the proxy, separated by commas or spaces. `example.com` and `.example.com` match the host and its subdomains, `*.example.com` matches only its subdomains, and `*` matches every host. Add `:port` to match a specific port. |
| `SONAR_CA_CERT`         | Path to a PEM file of additional CA certificates to trust, for example for an SSL-inspecting proxy.                                                                                                                                            |

`SONAR_HTTPS_PROXY_URL` takes precedence over the standard `HTTPS_PROXY` variable. The request to SonarQube Cloud is the scanner's only network call. Image export and SBOM generation run locally.

## Configuration options

Use the following options to configure the container scanner:

| Flag                                    | Values                                             | Default                                              | Description                                                                                                                                              |
| --------------------------------------- | -------------------------------------------------- | ---------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `--organization`                        | Organization key                                   | -                                                    | SonarQube Cloud organization to scan under                                                                                                               |
| `--token`                               | Token                                              | -                                                    | SonarQube Cloud user token                                                                                                                               |
| `--host-url`                            | URL                                                | `https://sonarcloud.io`                              | SonarQube Cloud instance to submit to, for example `https://sonarqube.us` for the US instance or `https://sonarqube.au` for the AU instance              |
| `--container-engine`                    | `docker`, `podman`                                 | `docker`, or `podman` if it's the only one installed | Container engine to export an image reference from. Ignored for `.tar` archives and OCI layout directories. Available from version 1.0.                  |
| `--registry` / `--repository` / `--tag` | Text                                               | Auto-detected                                        | Override the image identity. Pass `--registry` and `--repository` together.                                                                              |
| `--fail-on`                             | `none`, `info`, `low`, `medium`, `high`, `blocker` | `high`                                               | Exit with a failing code when risks at or above this severity are found                                                                                  |
| `--format`                              | `json`, `table`                                    | `json`                                               | CLI output format                                                                                                                                        |
| `--timeout-secs`                        | Integer, at least 1                                | `300`                                                | Timeout, in seconds, for the request to SonarQube Cloud, the image export, and the SBOM generation. When it's exceeded, the scanner exits with code `2`. |
| `-v` / `-vv`                            | -                                                  | Off                                                  | Debug logging                                                                                                                                            |
| `-V` / `--version`                      | -                                                  | -                                                    | Print the scanner version                                                                                                                                |
| `--help`                                | -                                                  | -                                                    | List all options                                                                                                                                         |

To print the licenses of the scanner and its bundled components, run `sonar-container-scanner licenses`. Add `--full` for the full license texts. This command needs no image or credentials.

## Viewing the results in SonarQube Cloud

1. Open your organization in SonarQube Cloud.
2. Select **Container images** in the sidebar.
3. You'll see every image analyzed in your organization, with its tag, the number of risks, the most severe risk, and when it was last analyzed. Use the search box to find an image, and **Sort by** to change the order.
4. Select an image to see its versions and their dependency risks. Manage risks with the same workflow you use for dependency risks in your projects.

### Keeping results up to date

SonarQube Cloud automatically re-checks analyzed images for newly published vulnerabilities, based on your organization's re-analysis settings. You do not need to re-scan an image to learn about new vulnerabilities in it.

To refresh an image's results after it changes, run the scanner again. On-demand re-scans from the UI are not available yet.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.sonarsource.com/sonarqube-cloud/advanced-security/container-scanning.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
