将Docker映像从gitlab

将Docker映像从gitlab

本文介绍了将Docker映像从gitlab-ci推送到Azure容器注册表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在docker(dind)中熟悉docker,但与 microsoft/azure-cli 图像抛出 docker命令未找到一起使用.

I am familiar with docker in docker (dind) but using along with microsoft/azure-cli image throw docker command not found.

这是我的 gitlab-ci.yml 文件的设置.我创建了 Service Principal ,用于对Azure云和相应的资源组进行身份验证.

Here is my setup for gitlab-ci.yml file. I have created Service Principal which is used to authenticate to azure cloud and respective resource group.

image: docker:latest

variables:
  PASSWORD: *********
  TENANT_ID: *****-************-*************
  APP_ID: *********-*****-*****
  CLIENT_ID: ****************
  ACR_ID: *******************


stages:
  - build
  - deploy

services:
  - docker:dind

before_script:
  - docker info

build_staging_image:
  stage: build
  image: microsoft/azure-cli
  script:
    - az login --service-principal --username $APP_ID --password $PASSWORD --tenant $TENANT_ID
    - docker build -t azure-vote:latest ./azure-vote
    - docker tag azure-vote votingtestapp.azurecr.io/azure-vote:latest
    - docker push votingtestapp.azurecr.io/azure-vote:latest



deploy:develop:
  stage: deploy
  script:
    - az login --service-principal --username $APP_ID --password $PASSWORD --tenant $TENANT_ID
    - az acr login --name votingTestApp
    - az role assignment create --assignee $CLIENT_ID --role Reader --scope $ACR_ID
    - kubectl apply -f azure-vote-all-in-one-redis.yaml
  only:
    - develop

任何解决此错误的方法.我只是试图创建CI/CD管道.

Any way to fix this error. I am just trying to create CI/CD pipeline.

推荐答案

问题是 microsoft/azure-cli docker映像确实安装了docker,并且docker套接字未安装到容器上.这 docker 命令将失败.

The problem is that microsoft/azure-cli docker image does have docker installed and the docker socket is not mounted onto the container. This the docker command will fail.

您仅使用 microsoft/azure-cli 登录到注册表.但请注意,您也可以使用 docker login 登录.检查登录到注册表.

You are using the microsoft/azure-cli just to login to the registery. But note that you can also login using docker login. Check Log in to a registry.

因此,要解决此问题,请使用 dind 图片并使用以下命令登录到天蓝色寄存器:

Therefore, to solve the issue use a dind image and login to azure register using:

docker login myregistry.azurecr.io -u xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx -p myPassword

这篇关于将Docker映像从gitlab-ci推送到Azure容器注册表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 19:31