簡體   English   中英

gitlab在ci文件中使用Container Registry的鏈接時會提示找不到docker

[英]gitlab when I use the link of Container Registry in the ci file, I will be prompted that the docker is not found

.gitlab-ci.yml

workflow:
  rules:
    - if: $CI_COMMIT_BRANCH != "main" && $CI_PIPELINE_SOURCE != "merge_request_event" 
      when: never
    - when: always


variables:
  IMAGE_NAME: $CI_REGISTRY_IMAGE


stages:
  - test
  - build



run_unit_tests:
  image: node:16-alpine3.17
  stage: test
  tags:
    - txy
  before_script:
    - cd app
    - npm install
  script: 
    - npm test
  artifacts:
    when: always
    paths:
      - app/junit.xml
    reports:
      junit: app/junit.xml


build_image:
  stage: build
  tags: 
    - remoteone
  before_script:
    - echo "Docker registry url is $CI_REGISTRY"
    - echo "Docker registry username is $CI_REGISTRY_USER"
    - echo "Docker registry repo is $CI_REGISTRY_IMAGE"
  script:
    - docker build -t $IMAGE_NAME .


push_image:
  stage: build
  needs: 
    - build_image
  tags:
    - remoteone
  before_script:
    - echo "Docker registry url is $CI_REGISTRY"
    - echo "Docker registry username is $CI_REGISTRY_USER"
    - echo "Docker registry repo is $CI_REGISTRY_IMAGE"
    - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
  script: 
    - docker push $IMAGE_NAME


在此處輸入圖像描述

上述變量的對應關系

$CI_REGISTRY_IMAGE = docker build -t registry.gitlab.com/komorebi-cqd/mynodeapp-cicd-project。

$CI_REGISTRY = docker push registry.gitlab.com/komorebi-cqd/mynodeapp-cicd-project

文件

FROM node:16-alpine
RUN apk add docker-cli

WORKDIR /usr/src/app

COPY ./app/package*.json ./
RUN npm install
COPY ./app .

EXPOSE 3000
CMD [ "npm" ,"start"]

cicd管道build_image錯誤

Running with gitlab-runner 15.5.1 (7178588d)
  on one-docker-runner fAyvKeBR
Preparing the "docker" executor
00:03
Using Docker executor with image alpine:3.14 ...
Pulling docker image alpine:3.14 ...
Using docker image sha256:dd53f409bf0bd55eac632f9e694fd190244fef5854a428bf3ae1e2b636577623 for alpine:3.14 with digest alpine@sha256:4c869a63e1b7c0722fed1e402a6466610327c3b83bdddb94bd94fb71da7f638a ...
Preparing environment
00:01
Running on runner-fayvkebr-project-41046722-concurrent-0 via VM-20-2-ubuntu...
Getting source from Git repository
00:02
Fetching changes with git depth set to 20...
Reinitialized existing Git repository in /builds/komorebi-cqd/mynodeapp-cicd-project/.git/
Checking out 023ee3af as main...
Removing app/junit.xml
Skipping Git submodules setup
Downloading artifacts
00:03
Downloading artifacts for run_unit_tests (3502740847)...
Downloading artifacts from coordinator... ok        id=3502740847 responseStatus=200 OK token=64_pVtH2
Executing "step_script" stage of the job script
00:01
Using docker image sha256:dd53f409bf0bd55eac632f9e694fd190244fef5854a428bf3ae1e2b636577623 for alpine:3.14 with digest alpine@sha256:4c869a63e1b7c0722fed1e402a6466610327c3b83bdddb94bd94fb71da7f638a ...
$ echo "Docker registry url is $CI_REGISTRY"
Docker registry url is registry.gitlab.com
$ echo "Docker registry username is $CI_REGISTRY_USER"
Docker registry username is gitlab-ci-token
$ echo "Docker registry repo is $CI_REGISTRY_IMAGE"
Docker registry repo is registry.gitlab.com/komorebi-cqd/mynodeapp-cicd-project
$ docker build -t $IMAGE_NAME .
/bin/sh: eval: line 137: docker: not found
Cleaning up project directory and file based variables
00:00
ERROR: Job failed: exit code 127

提示docker: not found,網上找了半天也沒有具體解決辦法

我的服務器上安裝了Docker,運行Docker PS沒有問題。 但是,當我使用gitlab registry時,會提示Docker不存在。 不知道是哪里的問題,網上也沒有相應的解決辦法。 我希望有人能告訴我為什么找不到 Docker 以及如何解決它。

GitLab CI使用Docker來運行您的管道(使用Docker 執行器),但這並不意味着Docker可以從 CI 容器內部使用。

你可以從 CI 輸出中看到它使用alpine:3.14 Docker 鏡像來運行你的命令,不幸的是這個鏡像沒有安裝Docker

Using Docker executor with image alpine:3.14 ...

GitLab 文檔描述了 3 種使用 CI 構建 Docker 鏡像的方法:

  • 外殼執行器
  • Docker-in-DockerDockerKubernetes 執行器
  • Docker套接字綁定

我會說使用Docker-in-Docker方法,因為其他 2 個方法可能會導致並發問題:並發管道將使用相同的Docker 守護進程,這可能會導致 Docker對象的命名沖突。


如果有幫助,您可以閱讀更多關於我在 2020 年在 GitLab CI 中構建 Docker 鏡像的個人經歷。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM