无法从Gitlab CI访问私有MySQL Docker映像 [英] Can't Access Private MySQL Docker Image From Gitlab CI

查看:61
本文介绍了无法从Gitlab CI访问私有MySQL Docker映像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试从Docker Hub存储库中将私有(自定义)MySQL映像作为服务引入gitlab-ci.yml管道。我添加了一个before_script尝试使用我的用户名和密码(CI变量)登录dockerhub。失败的构建日志中没有输出提示是否成功登录Docker Hub,但我假设不是因为我的映像提取失败并显示以下消息(编辑:或者甚至从未尝试过,因为gitlab试图获取服务运行它之前的脚本?):



存储库不存在或可能需要'docker login'(executor_docker.go:168:0s)



我正在使用共享运行器(因为我相信这是我使用gitlab.com的唯一选择?)
我已经看到很多关于docker的gitlab ci令牌的信息,但是我找不到任何文档来解释如何简化此操作。



我确定我只是在忽略某些内容/不理解或在搜索中遇到合适的解决方案,因此抱歉,如果我只是没有经验,并在此先感谢您的帮助。



我的gitlab-ci(Maven变量是因为该项目的构建依赖于私有Maven回购数据库和redis主机变量在运行时注入到我的应用程序中,因此它们知道指向哪个容器)

  image:maven:3.5 .0-jdk-8 

before_script:
- docker login -u $ DOCKER_USER -p $ DOCKER_PASS#管道变量

变量:
MAVEN_CLI_OPTS: -s .m2 / settings.xml --batch-mode
MAVEN_OPTS: -Dmaven.repo.local = .m2 / repository
DATABASE_HOST:mysql
REDIS_HOST:redis

服务:
-名称:privaterepo / private-mysql-schema
别名:mysql
-名称:redis:最新
别名:redis

阶段:
-生成

maven-build:
阶段:build
脚本: mvn $ MAVEN_CLI_OPTS package -B
工件:
路径:
-目标/*.jar


解决方案

第一件事是设置GitLab CI,以在需要时提供私有Docker注册表的凭据。为此,需要


I've been trying to pull in a private (custom) MySQL image from my Docker Hub repository to the gitlab-ci.yml pipeline as a service. I have added a before_script that tries to log in to dockerhub with my username and password (CI variables). There's no output in the failed build log suggesting whether the login to Docker Hub was successful or otherwise but I'm assuming not because the pulling of my image fails with the following message (edit: or it's never even attempted because gitlab tries to get the services before it runs the before script?):

repository does not exist or may require 'docker login' (executor_docker.go:168:0s)

I am using a shared runner (because I believe that's my only option using gitlab.com?) I've seen quite a few mentions of the gitlab ci token for docker but I've found no documentation explaining how to facilitate this.

I'm sure I'm just overlooking something/not understanding or coming across the appropriate solution in my searches so apologies if I'm just being inexperienced and thanks in advance for any help.

My gitlab-ci (the maven variables are because this project's build has a dependency on a private maven repo. The database and redis host variables are injected into my app at runtime so they know which container to point to)

image: maven:3.5.0-jdk-8

before_script:
  - "docker login -u$DOCKER_USER -p$DOCKER_PASS" #pipeline variables

variables:
  MAVEN_CLI_OPTS: "-s .m2/settings.xml --batch-mode"
  MAVEN_OPTS: "-Dmaven.repo.local=.m2/repository"
  DATABASE_HOST: mysql
  REDIS_HOST: redis

services:
  - name: privaterepo/private-mysql-schema
    alias: mysql
  - name: redis:latest
    alias: redis

stages:
  - build

maven-build:
  stage: build
  script: "mvn $MAVEN_CLI_OPTS package -B"
  artifacts:
    paths:
      - target/*.jar

解决方案

First thing is to setup GitLab CI to provide credentials of the private docker registry when needed. To do that there is specific section in docs you should follow, to be a complete answer that is

  1. Get docker registry url, username and password using docker login or some other manner (I had to spend sometime to figure out registry for the docker hub)
  2. Define DOCKER_AUTH_CONFIG variable in GitLab CI variable section it would look like

{
    "auths": {
        "registry.hub.docker.com": {
            "auth": "xxxxxxxxxxxxxxxxxxxxxxxxxxxx" // base 64 encoded username:password
        }
    }
}

  1. Declare image/service image: registry.hub.docker.com/ruwanka/helloworld:0.1 in .gitlab-ci.yml

That should full fill the requirement of pulling images. There is another section in docs that lists the requirement of runner to allow list of services. If it doesn't specify any then it should be fine, you may have to tweak it if it doesn't work.

final yaml is look like below

image: registry.hub.docker.com/ruwanka/helloworld:0.1

build:
  script:
   - echo "hello"
# more steps   
services:
  - registry.hub.docker.com/ruwanka/helloworld:0.1

snippet of GitLab job's logs

这篇关于无法从Gitlab CI访问私有MySQL Docker映像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆