Gitlab:构建docker容器,然后使用它进行编译

Gitlab:构建docker容器,然后使用它进行编译,docker,gitlab-ci,gitlab-ci-runner,Docker,Gitlab Ci,Gitlab Ci Runner,这是我的.gitlab-ci.yml stages: - containerize - compile build_image: image: docker stage: containerize script: - docker build -t compiler_image_v0 . compile: image: compiler_image_v0 stage: compile script: - make artifacts:

这是我的.gitlab-ci.yml

stages:
   - containerize
   - compile

build_image:
  image: docker
  stage: containerize
  script:
    - docker build -t compiler_image_v0 .

compile:
  image: compiler_image_v0
  stage: compile
  script:
    - make
  artifacts:
    when: on_success
    paths:
      - output/
    expire_in: 1 day
build_image
运行正常,在运行程序所在的机器上使用
docker images
命令时,会列出创建的图像。但第二个作业失败,出现以下错误:

错误:作业失败:守护进程的错误响应:拒绝对编译器\u映像\u v0的拉取访问,存储库不存在或可能需要“docker登录”(executor\u docker.go:168:1s)

发生什么事了

这是我的
Dockerfile

FROM ubuntu:18.04

WORKDIR /app

# Ubuntu packages
RUN apt-get update
RUN DEBIAN_FRONTEND=noninteractive apt-get -y install apt-utils subversion g++ make cmake unzip
RUN DEBIAN_FRONTEND=noninteractive apt-get -y install libgtk2.*common libpango-1* libasound2* xserver-xorg
RUN DEBIAN_FRONTEND=noninteractive apt-get -y install cpio
RUN DEBIAN_FRONTEND=noninteractive apt-get -y install bash
RUN DEBIAN_FRONTEND=noninteractive apt-get -y install autoconf automake perl m4

# Intel Fortran compiler
RUN mkdir /intel
COPY parallel_studio_xe_2018_3_pro_for_docker.zip  /intel
RUN cd /intel && unzip /intel/parallel_studio_xe_2018_3_pro_for_docker.zip
RUN cd /intel/parallel_studio_xe_2018_3_pro_for_docker && ./install.sh --silent=custom_silent.cfg
RUN rm -rf /intel

stage compile尝试拉取映像
编译器\u image\u v0
。此映像仅临时存在于stage
containerize
的docker容器中。您的gitlab存储库中有一个容器注册表,可以在
containerize
阶段推送构建的映像,然后在
compile
阶段拉取它。此外:您应该提供私有gitlab注册表的全名。我认为dockerhub是默认使用的

您可以更改
.gitlab.ci.yaml
以添加push命令并使用完全命名的映像:

stages:
   - containerize
   - compile

build_image:
  image: docker
  stage: containerize
  script:
    - docker build -t compiler_image_v0 .
    - docker push registry.gitlab.com/group-name/repo-name:compiler_image_v0

compile:
  image: registry.gitlab.com/group-name/repo-name:compiler_image_v0
  stage: compile
  script:
    - make
  artifacts:
    when: on_success
    paths:
      - output/
    expire_in: 1 day

这将覆盖每个构建上的映像。但是您可以添加一些版本控制。

您真的想在每个构建上执行容器化阶段吗?你能发布你的Dockerfile吗?让我们假设我确实需要在每个构建上执行容器化阶段。我用Dockerfile更新了这个问题。好的,谢谢,我同意。但是我想澄清一下:你说图像只是临时的,那么为什么在runner主机上运行
docker images
时会出现它呢?我不知道该图像仍保留在主机上,所以这是我提供的错误信息。但这实际上取决于主机的配置或主机重置的时间。你自己管理跑步者主持人吗?我想象公共跑步者的主机会定期重置。作为旁注:您可能需要研究docker的多阶段构建。这也可以解决你的问题:如果我可以补充:如果可以,我会说不要在docker中使用docker。我不完全了解Gitlab作为非自托管的运行者提供了什么,但是shell executor会比dind更好,尽管Gitlab倾向于记录很多关于它的事情。。。多阶段构建也是一个很酷的特性。推送图像也是一种方式。如果你在控制你的跑步者的配置,你也可以考虑看看。