Pushing Docker image from gitlab-ci to Azure Container Registry

与世无争的帅哥 提交于 2021-01-27 10:43:21

问题


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

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

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


回答1:


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.

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.

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


来源:https://stackoverflow.com/questions/49324762/pushing-docker-image-from-gitlab-ci-to-azure-container-registry

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!