> ## Documentation Index
> Fetch the complete documentation index at: https://docs.endorlabs.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Scan containers using endorctl

> Learn how to scan container images using the endorctl container scan command for security vulnerabilities, dependencies, and compliance.

Container images contain multiple layers of software dependencies that introduce security risks across the entire software supply chain. The `endorctl container scan` command analyzes container images to identify vulnerabilities in base OS packages, runtime dependencies, and application libraries, providing comprehensive security visibility across all containerized workloads.

## Create finding policies for containers

Container base images from untrusted sources may lack proper security audits or fail to comply with organizational standards, increasing the risk of vulnerabilities being exploited. To address this, you can configure a finding policy to detect unauthorised base images and raise a critical finding.

For example, to allow only base images that start with `gcp` or `ghcr`, use the [Container policy template](/managing-policies/finding-policies/container-policies) and specify **Base Image Name Regex** as `^gcp`, `^ghcr`.

See [Create a finding policy from template](/managing-policies/finding-policies#create-a-finding-policy-from-template) for detailed instructions on creating finding policies.

<img src="https://mintcdn.com/endorlabs-b4795f4f/rtiT4oc3TglKX_HY/images/scan/containers/container-scan-policy.webp?fit=max&auto=format&n=rtiT4oc3TglKX_HY&q=85&s=6fc80bc63ae9b2d15e6b1fc82899d4fa" alt="Finding policy template for container base images" style={{ width: '70%' }} width="1832" height="1408" data-path="images/scan/containers/container-scan-policy.webp" />

## Perform the endorctl scan

Endor Labs supports the following methods of scanning container images:

* **[Scan container images in a Git repository](#scan-container-images-in-a-git-repository)**: Scan images built within your repository using a Dockerfile.

* **[Scan container images as a standalone project](#scan-container-images-as-a-standalone-project)**: Scan base or golden images that are shared across multiple repositories or applications.

* **[Scan container image tarball](#scan-container-image-tarball)**:  Scan images saved as tar files, such as base images exported from Docker, to generate dependency, SBOM, and vulnerability reports.

* **[Scan images from a container registry](/scan/containers/container-registry-scan)**: List and scan images directly from a registry such as AWS ECR, Azure ACR, Docker Hub, GHCR, or JFrog Artifactory.

### Scan container images in a Git repository

Run the following command to scan a container image built in a specific repository. Specify the project path using the `--path` argument and the container image name using the `--image` argument. This associates the container with the Git repository and branch of the project.

```bash theme={null}
endorctl container scan --image=<image_name:tag> --path=users/janedoe/endorlabs/npm/exampleproject
```

You can also scan multiple container images as part of a single repository.

```bash theme={null}
endorctl container scan --image=<image_name1:tag> --path=users/janedoe/endorlabs/npm/exampleproject
endorctl container scan --image=<image_name2:tag> --path=users/janedoe/endorlabs/npm/exampleproject
endorctl container scan --image=<image_name3:tag> --path=users/janedoe/endorlabs/npm/exampleproject
```

You can tag findings with the corresponding container image name and tag. This lets you filter container-related findings in the user interface or through the API.

```bash theme={null}
endorctl container scan --image=<image_name:tag> --path=users/janedoe/endorlabs/npm/exampleproject --finding-tags=<image_name:tag>
```

### Scan container images as a standalone project

Run the following command to scan a container image from a registry. Specify the project name using the `--project-name` argument, and the container image name and tag using the `--image` argument.

```bash theme={null}
endorctl container scan --image=<image_name:tag> --project-name=<endor_project_name>
```

To keep multiple versions of a container image in a container-only project, include the `--as-ref` flag.

```bash theme={null}
endorctl container scan --image=<image_name:tag> --project-name=<endor_project_name> --as-ref
```

You can tag findings with the corresponding container image name and tag. This lets you filter container-related findings in the user interface or through the API.

```bash theme={null}
endorctl container scan --project-name=<endor_project_name> --image=<image_name:tag> --as-ref --finding-tags=<image_name:tag>
```

<Note>
  **Important**

  To associate a container scan with an existing SCA scan for a project, you must use the `--path` argument specifying the same project  path used for the SCA scan. You cannot associate a container scan with an SCA scan for a project using the `--project-name` parameter.
</Note>

### Scan container image tarball

You can save a container image as a tarball and scan it with endorctl to generate a report containing dependencies, SBOM details, and security findings.

1. Ensure that you have the container image available locally.

   ```bash theme={null}
   docker pull alpine:latest
   ```

2. Export the image to a tarball file.

   ```bash theme={null}
   docker save alpine:latest -o alpine-latest.tar
   ```

3. Perform the endorctl scan.

   ```bash theme={null}
   endorctl container scan --image=alpine:latest --project-name=<endor_project_name> --image-tar=/absolute/path/to/alpine-latest.tar
   ```

   <Note>
     * `--image-tar` must point to the absolute path of the tarball file.
     * `--image=<name:tag>` is optional but recommended. It explicitly identifies the container image inside the tarball.
   </Note>

## Perform container scan in CI pipelines

You can integrate container scanning into CI pipelines to automatically detect vulnerabilities and ensure the security of container images during the build and deployment process.

To scan containers in CI pipelines using GitHub Actions, set the `scan_container` parameter to `true` in the GitHub Actions script. Additionally, you must provide the `image` parameter with the container image you want to scan.

See [Performing scans in CI/CD pipelines](/deployment/ci-scans) for more information.
