构建映像后,如何从.gitlab-ci.yml运行我的docker映像? [英] How do I run my docker image from .gitlab-ci.yml after building the image?

查看:458
本文介绍了构建映像后,如何从.gitlab-ci.yml运行我的docker映像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遵循了以下方法来构建docker映像: https://gitlab.com/guided-explorations/containers/kaniko-docker-build/-/blob/master/.gitlab-ci.yml

I followed how to builf the docker image from: https://gitlab.com/guided-explorations/containers/kaniko-docker-build/-/blob/master/.gitlab-ci.yml

该工作正常,在浏览器中使用gitlab进行测试时不会出错。

The job works and throws no error when tested using gitlab from browser.

但是现在我希望能够使用某些命令将图像作为容器运行

But now I want to be able to run the image as a container with some command

.gitlab-ci.yml

build-repo:
  extends: .build_with_kaniko
  environment:
    name: push-to-repo-registry
  tags:
    - shared-runner-tag

我需要添加到 .gitlab-ci.yml 中的内容文件,以便能够像从终端一样使用命令将图像作为容器运行:

What do I need to add to the .gitlab-ci.yml file to be able to run the image as a container with a command like I would from the terminal:

$sudo docker run --name <image_instance> -i -t <image_name> [some command]

我只是在寻找一种如何将图像作为容器运行的快速解决方案。
每个关于kaniko的指南(我必须在我的案例中使用它)仅谈论构建映像并将其推送到docker和gitlab注册表,但从未涉及如何运行它。

I'm just looking for a quick solution on how to run the image as a container. Every guide with regards to kaniko (I have to use it for my case) only speaks about building the image and pushing it to docker and the gitlab registry, but never on how to run it.

谢谢

推荐答案

在.gitlab-ci.yml中,您可以使用option在远程服务器上执行docker命令-H或环境变量DOCKER_HOST。您可以在此处上找到启用TLS并执行命令的文档。 / p>

In .gitlab-ci.yml, you can execute docker command on remote server using option -H or environment variable DOCKER_HOST. You can find the documentation to enable TLS and execute command on remote host here.

export DOCKER_HOST=tcp://<host>:<port>
export DOCKER_CERT_PATH=<certificate_dir>
export DOCKER_TLS_VERIFY=1
docker run -d <image>

编辑:当然,您需要在gitlab运行程序中安装docker。

Of course, you need to have docker installed in your gitlab runner.

这篇关于构建映像后,如何从.gitlab-ci.yml运行我的docker映像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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