本文介绍了检查docker在Gitlab CICD管道中运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用构建以下内容的Docker映像:我们的节点服务器。

I'm using Gitlab CI/CD to build Docker images of our Node server.

我想知道是否有一种方法可以测试图像的 docker run 正常

I am wondering if there is a way to test that docker run of the image was ok.

我们很少构建Docker,但是缺少一些文件/ env变量,因此无法启动服务器。

We've had few occasions where the Docker builds but it is missing some files/env variables and it fails to start the server.

有什么方法可以运行 docker 映像并测试它在CI / CD管道中是否正确启动?

Is there any way to run the docker image and test if it is starting up correctly in the CI/CD pipeline?

干杯。

推荐答案

使用Gitlab,您可以。

With Gitlab you are able to use a docker-runner.

检查:

这是该网站上的经典 yml

default:
  image:
    name: ruby:2.2
    entrypoint: ["/bin/bash"]

  services:
  - name: my-postgres:9.4
    alias: db-postgres
    entrypoint: ["/usr/local/bin/db-postgres"]
    command: ["start"]

  before_script:
  - bundle install

test:
  script:
  - bundle exec rake spec

如您所见,测试部分将在构建映像后执行,因此,您不必担心。 Gitlab在加载图像时应该检测到任何错误

As you see, the test sections will be executed after building the image, so, you should not have to worry about. Gitlab should detect any errors when loading the image



stages:
  - dockerStartup
  - build
  - test
  - deploy
  - dockerStop
job 0:
  stage: dockerStartup
  script:
    - docker build -t my-docker-image .
    - docker run my-docker-image /script/to/run/tests
[...] //your jobs here
job 5:
  stage: dockerStop
  script: docker stop whatever

这篇关于检查docker在Gitlab CICD管道中运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 15:11