將 Docker Scout 與 Circle CI 整合


以下範例會在 CircleCI 中被觸發時執行。觸發時,它會簽出「docker/scout-demo-service:latest」映像檔與標籤,然後使用 Docker Scout 建立 CVE 報告。

將以下內容新增至 .circleci/config.yml 檔案。

首先,設定其餘的工作流程。將以下內容新增至 YAML 檔案中

version: 2.1

jobs:
  build:
    docker:
      - image: cimg/base:stable
    environment:
      IMAGE_TAG: docker/scout-demo-service:latest

這定義了工作流程所使用的容器映像檔以及映像檔的環境變數。

將以下內容新增至 YAML 檔案以定義工作流程的步驟

steps:
  # Checkout the repository files
  - checkout
  
  # Set up a separate Docker environment to run `docker` commands in
  - setup_remote_docker:
      version: 20.10.24

  # Install Docker Scout and login to Docker Hub
  - run:
      name: Install Docker Scout
      command: |
        env
        curl -sSfL https://raw.githubusercontent.com/docker/scout-cli/main/install.sh | sh -s -- -b /home/circleci/bin
        echo $DOCKER_HUB_PAT | docker login -u $DOCKER_HUB_USER --password-stdin

  # Build the Docker image
  - run:
      name: Build Docker image
      command: docker build -t $IMAGE_TAG .
  
  # Run Docker Scout          
  - run:
      name: Scan image for CVEs
      command: |
        docker-scout cves $IMAGE_TAG --exit-code --only-severity critical,high

這會簽出儲存庫檔案,然後設定一個獨立的 Docker 環境以在其中執行指令。

它會安裝 Docker Scout、登入 Docker Hub、建置 Docker 映像檔,然後執行 Docker Scout 來產生 CVE 報告。它僅會顯示嚴重或高等級的弱點。

最後,為工作流程及其任務新增一個名稱

workflows:
  build-docker-image:
    jobs:
      - build
© . This site is unofficial and not affiliated with Kubernetes or Docker Inc.