[英]use image from gitlab Registry in CI
Could you tell me if I do it in correct way:你能告诉我我是否以正确的方式做:
Before I had had in .gitlab-ci.yml之前我有 .gitlab-ci.yml
same_task:
stage: deploy
image: python:3
script:
- python -V
Now I have:我现在有:
pep8:
stage: deploy
image: gitlablogin/projectname
script:
- python -V
and after this change job failed:在此更改作业失败后:
Running with gitlab-runner 11.4.2 (cf91d5e1)
on docker-auto-scale 72989761
Using Docker executor with image gitlablogin/projectname ...
Pulling docker image gitlablogin/projectname ...
ERROR: Job failed: Error response from daemon: pull access denied for gitlablogin/projectname, repository does not exist or may require 'docker login' (executor_docker.go:168:0s)
Is my usage of docker in context of gitlab CI and gitlab registry is correct?我在 gitlab CI 和 gitlab 注册表的上下文中使用 docker 是否正确? I also want to keep my docker file on same repo and build new image when samething change in Dockerfile, what will be the best way to do it?我还想将我的 docker 文件保留在同一个 repo 上,并在 Dockerfile 中的相同内容更改时构建新映像,最好的方法是什么?
Right now it is possible to use images from your gitlab registry without any special steps.现在可以使用 gitlab 注册表中的图像而无需任何特殊步骤。 Just build and push an image to your gitlab project container registry只需构建映像并将其推送到您的 gitlab 项目容器注册表
docker build -t registry.gitlab.com/gitlabProject/projectName:build .
docker push registry.gitlab.com/gitlabProject/projectName:build
and then just specify this image in your pipeline settings:然后只需在您的管道设置中指定此图像:
image: registry.gitlab.com/gitlabProject/projectName:build
Gitlab is able to pull this image using it's credentials: Gitlab 能够使用它的凭据来拉取这个镜像:
Preparing the "docker+machine" executor
00:46
Using Docker executor with image registry.gitlab.com/gitlabProject/projectName:build ...
Authenticating with credentials from job payload (GitLab Registry)
Pulling docker image registry.gitlab.com/gitlabProject/projectName:build ...
Using docker image sha256:e7e0f4f5fa8cff8a93b1f37ffd7dd0505946648246aa921dd457c06a1607304b for registry.gitlab.com/gitlabProject/projectName:build ...
More: https://docs.gitlab.com/runner/configuration/advanced-configuration.html#using-a-private-container-registry更多: https : //docs.gitlab.com/runner/configuration/advanced-configuration.html#using-a-private-container-registry
Your approach isn't far from what you want to achieve.您的方法与您想要实现的目标相差不远。 I believe what you are missing is this:我相信你缺少的是:
According to: https://docs.gitlab.com/ee/ci/docker/using_docker_images.html#what-is-an-image根据: https : //docs.gitlab.com/ee/ci/docker/using_docker_images.html#what-is-an-image
in order to use the image you have built for your CI you will first need to add it to runner's config.toml file as a service .为了使用您为 CI 构建的图像,您首先需要将它作为服务添加到运行程序的config.toml文件中。
Once you have done so you would be able to use the directive: image: my_image
完成后,您将能够使用指令: image: my_image
However, there's another option which you could do: you could login to your Docker registry, pull and run the CI Docker image and then you can exec inside where you will be running your pipeline.但是,您还有另一个选择:您可以登录到您的 Docker 注册表,拉取并运行 CI Docker 映像,然后您可以在将要运行管道的地方执行 exec。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.