如何将 GitLab CI 与自定义 Docker 映像一起使用?

Mar*_*dik 9 continuous-integration gitlab docker

我做了一个简单的Dockerfile

FROM openjdk
EXPOSE 8080
Run Code Online (Sandbox Code Playgroud)

并使用以下方法构建图像:

docker build -t test .
Run Code Online (Sandbox Code Playgroud)

我安装并配置了一个 docker GitLab CI runner,现在我想在我的test图像中使用这个 runner 。所以我写了以下.gitlab-ci.yml文件:

image: test

run:
  script:
    - echo "Hello world!"
Run Code Online (Sandbox Code Playgroud)

但令我失望的test是,没有找到我可以在我的机器上使用的本地图像。

Running with gitlab-ci-multi-runner 9.4.2 (6d06f2e)
  on martin-docker-rawip (70747a61)
Using Docker executor with image test ...
Using docker image sha256:fa91c6ea64ce4b9b44672c6e56eed8312d0ec2afc80730cbee7754bc448ea22b for predefined container...
Pulling docker image test ...
ERROR: Job failed: Error response from daemon: repository test not found: does not exist or no pull access
Run Code Online (Sandbox Code Playgroud)

我什至不知道发生了什么。我怎样才能让跑步者知道我制作的这张图片?

小智 7

我有同样的问题。我在这里找到了答案:https : //forum.gitlab.com/t/runner-cant-use-local-docker-images/5507/6

将以下内容添加到 /etc/gitlab-runner/config.toml

[runners.docker]
# more config for the runner here...
pull_policy = "if-not-present"
Run Code Online (Sandbox Code Playgroud)

更多信息:https : //docs.gitlab.com/runner/executors/docker.html#how-pull-policies-work

我的 Dockerfile

FROM node:latest
RUN apt-get update -y && apt-get install openssh-client rsync -y
Run Code Online (Sandbox Code Playgroud)

在 runner 上,我构建了图像:

docker build -t node_rsync .
Run Code Online (Sandbox Code Playgroud)

.gitlab-ci.yml使用这个亚军的项目。

image: node_rsync

job:
  stage: deploy
  before_script:
    # now in the custom docker image
    #- 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )'
    - mkdir -p ~/.ssh
    - eval $(ssh-agent -s)
    - '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
    - ssh-add <(tr '@' '\n' <<< "$STAGING_PRIVATE_KEY" | base64 --decode)
    # now in the custom docker image
    #- apt-get install -y rsync
  script:
    - rsync -rav -e ssh --exclude='.git/' --exclude='.gitlab-ci.yml' --delete-excluded ./ $STAGING_USER@$STAGING_SERVER:./deploy/
  only:
    - master
  tags:
    - ssh
Run Code Online (Sandbox Code Playgroud)