<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                # GitLab Container Registry > 原文:[https://docs.gitlab.com/ee/user/packages/container_registry/](https://docs.gitlab.com/ee/user/packages/container_registry/) * [Enable the Container Registry for your project](#enable-the-container-registry-for-your-project) * [Control Container Registry from within GitLab](#control-container-registry-from-within-gitlab) * [Control Container Registry for your project](#control-container-registry-for-your-project) * [Control Container Registry for your group](#control-container-registry-for-your-group) * [Image Repository details page](#image-repository-details-page) * [Use images from GitLab Container Registry](#use-images-from-gitlab-container-registry) * [Authenticating to the GitLab Container Registry](#authenticating-to-the-gitlab-container-registry) * [Build and push images from your local machine](#build-and-push-images-from-your-local-machine) * [Build and push images using GitLab CI/CD](#build-and-push-images-using-gitlab-cicd) * [Authenticating to the Container Registry with GitLab CI/CD](#authenticating-to-the-container-registry-with-gitlab-cicd) * [Container Registry examples with GitLab CI/CD](#container-registry-examples-with-gitlab-cicd) * [Using a Docker-in-Docker image from your Container Registry](#using-a-docker-in-docker-image-from-your-container-registry) * [Delete images](#delete-images) * [Delete images from within GitLab](#delete-images-from-within-gitlab) * [Delete images using the API](#delete-images-using-the-api) * [Delete images using GitLab CI/CD](#delete-images-using-gitlab-cicd) * [Delete images by using a cleanup policy](#delete-images-by-using-a-cleanup-policy) * [Cleanup policy](#cleanup-policy) * [Managing project cleanup policy through the UI](#managing-project-cleanup-policy-through-the-ui) * [Troubleshooting cleanup policies](#troubleshooting-cleanup-policies) * [Managing project cleanup policy through the API](#managing-project-cleanup-policy-through-the-api) * [Use with external container registries](#use-with-external-container-registries) * [Regex pattern examples](#regex-pattern-examples) * [Use the Container Registry to store Helm Charts](#use-the-container-registry-to-store-helm-charts) * [Limitations](#limitations) * [Troubleshooting the GitLab Container Registry](#troubleshooting-the-gitlab-container-registry) * [Docker connection error](#docker-connection-error) * [Troubleshoot as a GitLab server admin](#troubleshoot-as-a-gitlab-server-admin) * [Unable to change path or transfer a project](#unable-to-change-path-or-transfer-a-project) # GitLab Container Registry[](#gitlab-container-registry "Permalink") 版本歷史 * 在 GitLab 8.8 中[引入](https://gitlab.com/gitlab-org/gitlab-foss/-/merge_requests/4040) . * 在 GitLab 8.9 中添加了 Docker Registry manifest `v1`支持,以支持 1.10 之前的 Docker 版本. * 從 GitLab 8.12 開始,如果您的帳戶中啟用了 2FA,則需要傳遞[個人訪問令牌(](../../profile/personal_access_tokens.html)而不是密碼)才能登錄到 GitLab 的 Container Registry. * 在 GitLab 9.1 中添加了多級圖像名稱支持. * 組級容器注冊表是在 GitLab 12.10 中[引入的](https://gitlab.com/gitlab-org/gitlab/-/issues/23315) . * 在 GitLab 13.0 中[引入](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/31322)了按圖像存儲庫名稱搜索. **注意:**本文檔是用戶指南. 要了解如何在整個 GitLab 實例上啟用 GitLab 容器注冊表,請訪問[管理員文檔](../../../administration/packages/container_registry.html) . 通過將 Docker 容器注冊表集成到 GitLab 中,每個項目都可以擁有自己的空間來存儲其 Docker 映像. 您可以在[https://docs.docker.com/registry/introduction/上](https://s0docs0docker0com.icopy.site/registry/introduction/)了解有關 Docker Registry 的更多信息. [![Container Registry repositories](https://img.kancloud.cn/f7/ec/f7eccbf7b70693671232729169b1b731_1366x1024.png)](img/container_registry_repositories_v13_1.png) ## Enable the Container Registry for your project[](#enable-the-container-registry-for-your-project "Permalink") **警告:**容器注冊表遵循項目的可見性設置. 如果項目是公開的,則容器注冊表也是如此. If you cannot find the **包和注冊表>容器注冊表** entry under your project’s sidebar, it is not enabled in your GitLab instance. Ask your administrator to enable GitLab Container Registry following the [administration documentation](../../../administration/packages/container_registry.html). 如果您使用的是 GitLab.com,則默認情況下啟用此功能,因此您可以立即開始使用注冊表. 當前,作為[存儲庫大小限制的](../../project/repository/index.html)一部分,GitLab.com 上的 Registry 有一個軟的(10GB)大小限制. 為您的 GitLab 實例啟用后,要為您的項目啟用 Container Registry: 1. 轉到項目的**"設置">"常規"**頁面. 2. 展開" **可見性","項目功能","權限"**部分,并在項目上啟用" **容器注冊表"**功能. 對于新項目,默認情況下可以啟用. 對于現有項目(GitLab 8.8 之前的版本),您必須顯式啟用它. 3. 按**保存更改**以使更改生效. 現在,您應該能夠在側欄中看到**Packages&Registries> Container Registry**鏈接. ## Control Container Registry from within GitLab[](#control-container-registry-from-within-gitlab "Permalink") GitLab 提供了一個簡單的 Container Registry 管理面板. 該管理面板可用于項目和組. ### Control Container Registry for your project[](#control-container-registry-for-your-project "Permalink") 導航到您項目的 **包裹和注冊>集裝箱注冊** . [![Container Registry project repositories](https://img.kancloud.cn/03/33/0333bd4212407b80f62c9f8192ed81ce_1366x1024.png)](img/container_registry_repositories_with_quickstart_v13_1.png) 該視圖將: * 顯示屬于該項目的所有圖像存儲庫. * 允許您按圖像存儲庫的名稱過濾. * 允許您[刪除](#delete-images-from-within-gitlab)一個或多個圖像存儲庫. * 允許您導航到圖像存儲庫詳細信息頁面. * 顯示具有最常用命令的**快速入門**下拉列表,以登錄,構建和推送 * (可選)如果為該項目啟用了[清理策略](#cleanup-policy) ,則將顯示橫幅. ### Control Container Registry for your group[](#control-container-registry-for-your-group "Permalink") 導航到您小組的 **包裹和注冊>集裝箱注冊** . [![Container Registry group repositories](https://img.kancloud.cn/86/f7/86f7f0f084b7972d6a86e80e11b9c33c_1366x1024.png)](img/container_registry_group_repositories_v13_1.png) 該視圖將: * Show all the image repositories of the projects that belong to this group. * 允許[刪除](#delete-images-from-within-gitlab)一個或多個圖像存儲庫. * 允許導航到特定的圖像存儲庫詳細信息頁面. ### Image Repository details page[](#image-repository-details-page "Permalink") 單擊任何圖像存儲庫的名稱將導航到詳細信息. [![Container Registry project repository details](https://img.kancloud.cn/0b/98/0b98eb1503944120209cbf1b7f37997f_1246x577.png)](img/container_registry_repository_details_v13.0.png) **注意:**下一頁在**組級別容器注冊表**和**項目級別容器注冊表中**具有相同的功能. 此視圖: * 顯示所有圖像存儲庫詳細信息. * 顯示圖像存儲庫的所有標記. * 允許您快速復制標簽路徑(通過單擊標簽名稱附近的剪貼板按鈕). * 允許您[刪除一個或多個標簽](#delete-images-from-within-gitlab) . ## Use images from GitLab Container Registry[](#use-images-from-gitlab-container-registry "Permalink") 要從 GitLab 容器注冊表中托管的映像下載并運行容器,請使用`docker run` : ``` docker run [options] registry.example.com/group/project/image [arguments] ``` 有關運行 Docker 容器的更多信息,請訪問[Docker 文檔](https://s0docs0docker0com.icopy.site/engine/userguide/intro/) . ## Authenticating to the GitLab Container Registry[](#authenticating-to-the-gitlab-container-registry "Permalink") 如果訪問項目菜單下的**Packages&Registries> Container Registry**鏈接,則可以看到使用 GitLab 憑據登錄到 Container Registry 的明確說明. 例如,如果注冊表的 URL 是`registry.example.com` ,那么您應該能夠使用以下命令登錄: ``` docker login registry.example.com ``` **注意:**如果您的帳戶中啟用了[2 因子身份驗證](../../profile/account/two_factor_authentication.html) ,則需要傳遞[個人訪問令牌(](../../profile/personal_access_tokens.html)而不是密碼)才能登錄到 GitLab 的 Container Registry. 如果項目是私有項目,則需要提供憑據進行授權. 有兩種方法可以做到這一點: * 通過使用[個人訪問令牌](../../profile/personal_access_tokens.html) . * 通過使用[部署令牌](../../project/deploy_tokens/index.html) . 兩者所需的最小范圍是`read_registry` . 使用令牌的示例: ``` docker login registry.example.com -u <username> -p <token> ``` ## Build and push images from your local machine[](#build-and-push-images-from-your-local-machine "Permalink") 建立和發布圖像應該是一個簡單的過程. 只需確保您將注冊表 URL 與 GitLab 上托管的名稱空間和項目名稱一起使用即可: ``` docker build -t registry.example.com/group/project/image . docker push registry.example.com/group/project/image ``` 您的圖片將按照以下方案命名: ``` <registry URL>/<namespace>/<project>/<image> ``` GitLab 最多支持三個級別的圖像存儲庫名稱. 以下圖像標簽示例有效: ``` registry.example.com/group/project:some-tag registry.example.com/group/project/image:latest registry.example.com/group/project/my/image:rc1 ``` ## Build and push images using GitLab CI/CD[](#build-and-push-images-using-gitlab-cicd "Permalink") While you can build and push your images from your local machine, the true power of the Container Registry comes when you combine it with GitLab CI/CD. You can then create workflows and automate any processes that involve testing, building, and eventually deploying your project from the Docker image you created. 在深入研究細節之前,您應該注意一些事項: * 運行任何命令之前,必須[先向容器注冊表](#authenticating-to-the-container-registry-with-gitlab-cicd)進行[身份驗證](#authenticating-to-the-container-registry-with-gitlab-cicd) . 如果有多個作業依賴于它,則可以在`before_script`執行此操作. * 使用`docker build --pull`在構建之前獲取對基礎映像的所有更改,以防緩存過時. 它花費的時間稍長一些,但這意味著如果沒有基礎映像的安全補丁,您將不會陷入困境. * 在每次`docker run` docker 之前進行顯式`docker pull`都會獲取剛剛構建的最新映像. 如果您正在使用多個在本地緩存圖像的運行程序,則這一點尤其重要. 在圖像標簽中使用 Git SHA 使得此操作變得不必要,因為每個作業都是唯一的,并且您永遠都不會過時的圖像. 但是,如果在依賴項發生更改后重新構建給定的提交,則仍然可能會有陳舊的映像. * 如果有多個作業同時發生,則您不想直接構建到`latest`標記. ### Authenticating to the Container Registry with GitLab CI/CD[](#authenticating-to-the-container-registry-with-gitlab-cicd "Permalink") 通過[GitLab CI / CD](../../../ci/yaml/README.html)向容器注冊表進行身份驗證的三種方法取決于您項目的可見性. 適用于所有項目,但更適合公共項目: * **使用特殊的`CI_REGISTRY_USER`變量** :為您創建此變量指定的用戶,以便推送到連接到您的項目的注冊表. 它的密碼是使用`CI_REGISTRY_PASSWORD`變量自動設置的. 這使您可以自動構建和部署 Docker 映像,并具有對注冊表的讀/寫訪問權限. 這是短暫的,因此僅適用于一項工作. 您可以按原樣使用以下示例: ``` docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY ``` 對于私人和內部項目: * **使用個人訪問令牌** :如果您的項目是私有的,則可以創建和使用[個人訪問令牌](../../profile/personal_access_tokens.html) : * 對于讀取(拉)訪問,范圍應為`read_registry` . * 要進行讀/寫(拉/推)訪問,請使用`api` . Replace the `<username>` and `<access_token>` in the following example: ``` docker login -u <username> -p <access_token> $CI_REGISTRY ``` * **使用 GitLab 部署令牌** :您可以在私有項目中創建和使用[特殊的部署令牌](../../project/deploy_tokens/index.html#gitlab-deploy-token) . 它提供對注冊表的只讀(拉)訪問. 創建后,您可以使用特殊的環境變量,GitLab CI / CD 將為您填充它們. 您可以按原樣使用以下示例: ``` docker login -u $CI_DEPLOY_USER -p $CI_DEPLOY_PASSWORD $CI_REGISTRY ``` ### Container Registry examples with GitLab CI/CD[](#container-registry-examples-with-gitlab-cicd "Permalink") 如果您在 Runners 上使用 Docker-in-Docker,則`.gitlab-ci.yml`外觀應與此類似: ``` build: image: docker:19.03.12 stage: build services: - docker:19.03.12-dind script: - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY - docker build -t $CI_REGISTRY/group/project/image:latest . - docker push $CI_REGISTRY/group/project/image:latest ``` 您還可以利用[其他變量](../../../ci/variables/README.html)來避免硬編碼: ``` build: image: docker:19.03.12 stage: build services: - docker:19.03.12-dind variables: IMAGE_TAG: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG script: - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY - docker build -t $IMAGE_TAG . - docker push $IMAGE_TAG ``` 在這里, `$CI_REGISTRY_IMAGE`將解析為與此項目`$CI_REGISTRY_IMAGE`的注冊表的地址. 由于`$CI_COMMIT_REF_NAME`解析為分支名稱或標記名稱,并且您的分支名稱可以包含正斜杠(例如,feature / my-feature),因此將`$CI_COMMIT_REF_SLUG`用作圖像標記`$CI_COMMIT_REF_SLUG`安全. 這是因為圖像標記不能包含正斜杠. 我們還聲明了自己的變量`$IMAGE_TAG` ,將兩者結合起來可以節省一些在`script`部分鍵入的內容. 這是一個更詳細的示例,將任務分為 4 個管道階段,包括兩個并行運行的測試. 內部`build`存儲在容器注冊表中,供后續階段使用,并在需要時下載映像. 對`master`所做的更改也將被標記為`latest`并使用特定于應用程序的部署腳本進行部署: ``` image: docker:19.03.12 services: - docker:19.03.12-dind stages: - build - test - release - deploy variables: # Use TLS https://docs.gitlab.com/ee/ci/docker/using_docker_build.html#tls-enabled DOCKER_HOST: tcp://docker:2376 DOCKER_TLS_CERTDIR: "/certs" CONTAINER_TEST_IMAGE: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG CONTAINER_RELEASE_IMAGE: $CI_REGISTRY_IMAGE:latest before_script: - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY build: stage: build script: - docker build --pull -t $CONTAINER_TEST_IMAGE . - docker push $CONTAINER_TEST_IMAGE test1: stage: test script: - docker pull $CONTAINER_TEST_IMAGE - docker run $CONTAINER_TEST_IMAGE /script/to/run/tests test2: stage: test script: - docker pull $CONTAINER_TEST_IMAGE - docker run $CONTAINER_TEST_IMAGE /script/to/run/another/test release-image: stage: release script: - docker pull $CONTAINER_TEST_IMAGE - docker tag $CONTAINER_TEST_IMAGE $CONTAINER_RELEASE_IMAGE - docker push $CONTAINER_RELEASE_IMAGE only: - master deploy: stage: deploy script: - ./deploy.sh only: - master ``` **注意:**此示例顯式調用`docker pull` . 如果您希望使用`image:`隱式拉出構建的映像,并使用[Docker](https://docs.gitlab.com/runner/executors/docker.html)或[Kubernetes](https://docs.gitlab.com/runner/executors/kubernetes.html)執行程序,請確保[`pull_policy`](https://docs.gitlab.com/runner/executors/docker.html)設置為`always` . ### Using a Docker-in-Docker image from your Container Registry[](#using-a-docker-in-docker-image-from-your-container-registry "Permalink") 如果要為 Docker-in-Docker 使用自己的 Docker 映像,除了[Docker-in-Docker](../../../ci/docker/using_docker_build.html#use-docker-in-docker-workflow-with-docker-executor)部分中的步驟外,還需要做一些其他事情: 1. 更新`image`和`service`以指向您的注冊表. 2. 添加服務[別名](../../../ci/yaml/README.html#servicesalias) . 以下是您的`.gitlab-ci.yml`外觀示例: ``` build: image: $CI_REGISTRY/group/project/docker:19.03.12 services: - name: $CI_REGISTRY/group/project/docker:19.03.12-dind alias: docker stage: build script: - docker build -t my-docker-image . - docker run my-docker-image /script/to/run/tests ``` 如果您忘記設置服務別名,則`docker:19.03.12`映像將找不到`dind`服務,并且將引發類似以下的錯誤: ``` error during connect: Get http://docker:2376/v1.39/info: dial tcp: lookup docker on 192.168.0.1:53: no such host ``` ## Delete images[](#delete-images "Permalink") 您可以通過多種方式從 Container Registry 中刪除圖像. **警告:**刪除圖像是一種破壞性行為,無法撤消. 要還原已刪除的圖像,必須重建并重新上傳它.**注意:**管理員應查看如何[垃圾收集](../../../administration/packages/container_registry.html#container-registry-garbage-collection)刪除的圖像. ### Delete images from within GitLab[](#delete-images-from-within-gitlab "Permalink") 要從 GitLab 中刪除圖像: 1. Navigate to your project’s or group’s **包和注冊表>容器注冊表**. 2. 在" **容器注冊表"**頁面上,可以通過以下任一方法選擇要刪除的內容: * 通過單擊紅色刪除整個存儲庫及其包含的所有標簽 **垃圾桶**圖標. * 導航到存儲庫,然后通過單擊紅色單獨或批量刪除標簽 您要刪除的標簽旁邊的**垃圾桶**圖標. 3. 在對話框中,點擊**刪除標簽** . [![Container Registry tags](https://img.kancloud.cn/0b/98/0b98eb1503944120209cbf1b7f37997f_1246x577.png)](img/container_registry_repository_details_v13.0.png) ### Delete images using the API[](#delete-images-using-the-api "Permalink") 如果要自動執行刪除圖像的過程,GitLab 提供了一個 API. 有關更多信息,請參見以下端點: * [Delete a Registry repository](../../../api/container_registry.html#delete-registry-repository) * [Delete an individual Registry repository tag](../../../api/container_registry.html#delete-a-registry-repository-tag) * [Delete Registry repository tags in bulk](../../../api/container_registry.html#delete-registry-repository-tags-in-bulk) ### Delete images using GitLab CI/CD[](#delete-images-using-gitlab-cicd "Permalink") **警告:** GitLab CI / CD 沒有提供刪除圖像的內置方法,但是本示例使用了名為[reg](https://github.com/genuinetools/reg)的第三方工具,該工具與 GitLab Registry API 進行通信. 您應對自己的行為負責. 有關此工具的幫助,請參見[reg 的發行隊列](https://github.com/genuinetools/reg/issues) . 以下示例定義了兩個階段: `build`和`clean` . `build_image`作業將為分支構建 Docker 映像,而`delete_image`作業將其刪除. `reg`可執行文件已下載并用于刪除與`$CI_PROJECT_PATH:$CI_COMMIT_REF_SLUG` [環境變量](../../../ci/variables/predefined_variables.html)匹配的映像. 要使用此示例,請更改`IMAGE_TAG`變量以符合您的需求: ``` stages: - build - clean build_image: image: docker:19.03.12 stage: build services: - docker:19.03.12-dind variables: IMAGE_TAG: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG script: - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY - docker build -t $IMAGE_TAG . - docker push $IMAGE_TAG only: - branches except: - master delete_image: image: docker:19.03.12 stage: clean services: - docker:19.03.12-dind variables: IMAGE_TAG: $CI_PROJECT_PATH:$CI_COMMIT_REF_SLUG REG_SHA256: ade837fc5224acd8c34732bf54a94f579b47851cc6a7fd5899a98386b782e228 REG_VERSION: 0.16.1 before_script: - apk add --no-cache curl - curl --fail --show-error --location "https://github.com/genuinetools/reg/releases/download/v$REG_VERSION/reg-linux-amd64" --output /usr/local/bin/reg - echo "$REG_SHA256 /usr/local/bin/reg" | sha256sum -c - - chmod a+x /usr/local/bin/reg script: - /usr/local/bin/reg rm -d --auth-url $CI_REGISTRY -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $IMAGE_TAG only: - branches except: - master ``` **提示:**您可以從[發布頁面](https://github.com/genuinetools/reg/releases)下載最新的`reg`版本,然后通過更改`delete_image`作業中定義的`REG_SHA256`和`REG_VERSION`變量來更新代碼示例. ### Delete images by using a cleanup policy[](#delete-images-by-using-a-cleanup-policy "Permalink") 您可以創建每個項目的[清理策略,](#cleanup-policy)以確保定期從 Container Registry 中刪除較舊的標記和圖像. ## Cleanup policy[](#cleanup-policy "Permalink") 版本歷史 * 在 GitLab 12.8 中[引入](https://gitlab.com/gitlab-org/gitlab/-/issues/15398) . * 在 GitLab 13.2 中從"過期策略" [重命名](https://gitlab.com/gitlab-org/gitlab/-/issues/218737)為"清理策略". 對于特定項目,如果要刪除不再需要的標簽,則可以創建清除策略. 應用該策略時,將刪除與正則表達式模式匹配的標記. 底層和圖像仍然保留. 要刪除不再與任何標簽關聯的基礎層和圖像,實例管理員可以通過`-m`開關使用[垃圾回收](../../../administration/packages/container_registry.html#removing-unused-layers-not-referenced-by-manifests) . **注意:**對于 GitLab.com,清理策略不適用于將該功能部署到生產之前(2020 年 2 月)創建的項目. 計劃在 GitLab.com 上[為](https://gitlab.com/gitlab-org/gitlab/-/issues/196124)現有項目提供支持. 對于自我管理的實例,管理員可以在[GitLab 應用程序設置中](../../../api/settings.html#change-application-settings)通過將`container_expiration_policies_enable_historic_entries`設置為 true 來啟用清除策略. 注意[涉及](./index.html#use-with-external-container-registries)的固有[風險](./index.html#use-with-external-container-registries) . 清理策略算法首先從列表中收集給定存儲庫的所有標記,然后進行從標記中排除標記的過程,直到僅保留要刪除的標記為止: 1. 在列表中收集給定存儲庫的所有標記. 2. 排除名為標簽`latest`從列表中. 3. 評估`name_regex` ,從列表中排除不匹配的名稱. 4. 排除所有沒有清單的標簽(不是選項的一部分). 5. 按`created_date`其余標簽. 6. 從列表中排除基于`keep_n`值的 N 個標簽(要保留的標簽數). 7. 從列表中排除比`older_than`值(清除間隔)更新的標簽. 8. 從列表中排除與`name_regex_keep`值匹配的所有標簽(要保留的圖像). 9. 最后,列表中的其余標簽將從 Container Registry 中刪除. ### Managing project cleanup policy through the UI[](#managing-project-cleanup-policy-through-the-ui "Permalink") 要管理項目清理策略,請導航至 **設置> CI / CD>容器注冊表標記清除策略** . 用戶界面允許您配置以下內容: * **清理策略:**啟用或禁用清理策略. * **清除間隔:**標簽可以刪除多長時間. * **清理計劃:**檢查標簽的 cron 作業應運行的頻率. * **要保留的標簽數量:**每個圖像*始終*保留多少個標簽. * **名稱與該正則表達式模式匹配的 Docker 標簽將過期:**用于確定應清除哪些標簽的正則表達式. 要使所有標簽都合格,請使用默認值`.*` . * **名稱與該正則表達式模式匹配的 Docker 標簽將被保留:**用于確定應保留哪些標簽的正則表達式. 要保留所有標簽,請使用默認值`.*` . #### Troubleshooting cleanup policies[](#troubleshooting-cleanup-policies "Permalink") 如果看到以下消息: "更新清理策略時出了點問題." 檢查正則表達式模式以確保它們有效. 您可以使用[Rubular](https://rubular.com/)檢查您的正則表達式. 查看一些常見的[regex 模式示例](#regex-pattern-examples) . ### Managing project cleanup policy through the API[](#managing-project-cleanup-policy-through-the-api "Permalink") 您可以使用 GitLab API 設置,更新和禁用清理策略. Examples: * 選擇所有標簽,每個圖像至少保留 1 個標簽,清理超過 14 天的所有標簽,每月運行一次,使用名稱`master`保留所有圖像并啟用該策略: ``` curl --request PUT --header 'Content-Type: application/json;charset=UTF-8' --header "PRIVATE-TOKEN: <your_access_token>" --data-binary '{"container_expiration_policy_attributes":{"cadence":"1month","enabled":true,"keep_n":1,"older_than":"14d","name_regex":"","name_regex_delete":".*","name_regex_keep":".*-master"}}' 'https://gitlab.example.com/api/v4/projects/2' ``` 有關更多詳細信息,請參見 API 文檔: [編輯項目](../../../api/projects.html#edit-project) . ### Use with external container registries[](#use-with-external-container-registries "Permalink") 使用[外部容器注冊表時](./../../../administration/packages/container_registry.html#use-an-external-container-registry-with-gitlab-as-an-auth-endpoint) ,在項目上運行清除策略可能會帶來性能風險. 如果項目要運行的策略將刪除大量標簽(成千上萬個),則運行該策略的 GitLab 后臺作業可能會備份或完全失敗. 如果您確信要清除的標簽數量很少,建議僅對在 GitLab 12.8 之前創建的項目啟用容器清理策略. ### Regex pattern examples[](#regex-pattern-examples "Permalink") 清理策略使用正則表達式模式來確定應在 UI 和 API 中保留或刪除哪些標簽. 以下是您可能要使用的正則表達式模式的示例: * 匹配所有標簽: ``` .* ``` * 匹配以`v`開頭的標簽: ``` v.+ ``` * 匹配包含`master`標簽: ``` master ``` * 匹配以`v`開頭,包含`master`或包含`release`標簽: ``` (?:v.+|master|release) ``` ## Use the Container Registry to store Helm Charts[](#use-the-container-registry-to-store-helm-charts "Permalink") 隨著[Helm v3](https://helm.sh/docs/topics/registries/)的發布,您可以使用 Container Registry 存儲 Helm Charts. 但是,由于 Docker 傳遞和存儲元數據的方式,GitLab 無法解析此數據并達到性能標準. [本史詩](https://gitlab.com/groups/gitlab-org/-/epics/2313)更新了 Container Registry 的體系結構以支持 Helm Charts. 您可以[在此處](https://gitlab.com/gitlab-org/gitlab/-/issues/38047#note_298842890)閱讀有關上述挑戰的更多信息. ## Limitations[](#limitations "Permalink") * 推送圖像后,不支持移動或重命名現有 Container Registry 存儲庫,因為圖像已簽名,并且簽名包含存儲庫名稱. 要使用 Container Registry 移動或重命名存儲庫,必須刪除所有現有映像. * 在 GitLab 12.10 之前,清理策略不會刪除使用與`latest`標簽相同的圖像 ID 的任何標簽. ## Troubleshooting the GitLab Container Registry[](#troubleshooting-the-gitlab-container-registry "Permalink") ### Docker connection error[](#docker-connection-error "Permalink") 當組,項目或分支名??稱中包含特殊字符時,可能會發生 Docker 連接錯誤. 特殊字符可以包括: * 領先的下劃線 * 尾隨連字符/破折號 為了解決這個問題,您可以[更改組路徑](../../group/index.html#changing-a-groups-path) , [更改項目路徑](../../project/settings/index.html#renaming-a-repository)或更改分支名稱. ### Troubleshoot as a GitLab server admin[](#troubleshoot-as-a-gitlab-server-admin "Permalink") 大多數情況下,對 GitLab 容器注冊表進行故障排除需要管理員對 GitLab 服務器的訪問. [Read how to troubleshoot the Container Registry](../../../administration/packages/container_registry.html#troubleshooting). ### Unable to change path or transfer a project[](#unable-to-change-path-or-transfer-a-project "Permalink") 如果您嘗試更改項目的路徑或將項目轉移到新的名稱空間,則可能會收到以下錯誤之一: * "由于容器的注冊表中存在標簽,因此無法傳輸項目." * "無法移動名稱空間,因為至少一個項目在容器注冊表中具有標簽." 當項目在容器注冊表中有圖像時,會發生此問題. 必須先刪除或移動這些圖像,然后才能更改路徑或傳輸項目. 以下過程使用這些樣本項目名稱: * 對于當前項目: `example.gitlab.com/org/build/sample_project/cr:v2.9.1` : `example.gitlab.com/org/build/sample_project/cr:v2.9.1` * 對于新項目: `example.gitlab.com/new_org/build/new_sample_project/cr:v2.9.1` : `example.gitlab.com/new_org/build/new_sample_project/cr:v2.9.1` 使用您自己的 URL 完成以下步驟: 1. 將 Docker 映像下載到您的計算機上: ``` docker login example.gitlab.com docker pull example.gitlab.com/org/build/sample_project/cr:v2.9.1 ``` 2. 重命名圖像以匹配新的項目名稱: ``` docker tag example.gitlab.com/org/build/sample_project/cr:v2.9.1 example.gitlab.com/new_org/build/new_sample_project/cr:v2.9.1 ``` 3. 使用[UI](#delete-images)或[API](../../../api/packages.html#delete-a-project-package)刪除兩個項目中的圖像. 圖像排隊和刪除時可能會有延遲. 4. 通過轉到**"設置">"常規"**并展開" **高級"**來更改路徑或傳輸項目. 5. 恢復圖像: ``` docker push example.gitlab.com/new_org/build/new_sample_project/cr:v2.9.1 ``` 有關詳細信息,請關注[此問題](https://gitlab.com/gitlab-org/gitlab/-/issues/18383) .
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看