[英]How to use GitLab CI with a custom Docker image?
I made a simple Dockerfile
:我做了一个简单的Dockerfile
:
FROM openjdk
EXPOSE 8080
and built an image using:并使用以下方法构建图像:
docker build -t test .
I installed and configured a docker GitLab CI runner and now I would like to use this runner with my test
image.我安装并配置了一个 docker GitLab CI 运行器,现在我想将此运行器与我的test
图像一起使用。 So I wrote the following .gitlab-ci.yml
file:所以我写了以下.gitlab-ci.yml
文件:
image: test
run:
script:
- echo "Hello world!"
But to my disappointment, the local test
image that I can use on my machine was not found.但令我失望的是,我可以在我的机器上使用的本地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
I do not even know what is going on anymore.我什至不知道发生了什么。 How can I make the runner aware of this image that I made?我怎样才能让跑步者知道我制作的这张图片?
I had the same question.我有同样的问题。 And I found the answer here: https://forum.gitlab.com/t/runner-cant-use-local-docker-images/5507/6我在这里找到了答案: https : //forum.gitlab.com/t/runner-cant-use-local-docker-images/5507/6
Add the following in the /etc/gitlab-runner/config.toml
在/etc/gitlab-runner/config.toml
添加以下/etc/gitlab-runner/config.toml
[runners.docker]
# more config for the runner here...
pull_policy = "if-not-present"
More info here: https://docs.gitlab.com/runner/executors/docker.html#how-pull-policies-work更多信息: https : //docs.gitlab.com/runner/executors/docker.html#how-pull-policies-work
My Dockerfile
我的Dockerfile
FROM node:latest
RUN apt-get update -y && apt-get install openssh-client rsync -y
On the runner I build the image:在 runner 上,我构建了图像:
docker build -t node_rsync .
The .gitlab-ci.yml
in the project using this runner.使用此运行程序的项目中的.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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.