在 Gitlab CICD 管道中检查 docker 运行

Check docker run in Gitlab CICD pipeline

我正在使用 Gitlab CI/CD 构建 Docker 节点服务器的映像。

我想知道是否有办法测试 docker run 图片是否正常。

我们很少遇到 Docker 构建但缺少一些 files/env 变量并且无法启动服务器的情况。

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

干杯。

使用 Gitlab,您可以 use a docker-runner

When you use the docker-runner, and not a shell runner, a docker-like image and its services have to initiate, it should give an error if something fails.

this docs from gitlab:

这是来自该网络的经典 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 应该在加载图像时检测到任何错误

If you are doing it with the shell gitlab-runner, you should call the docker image start like this:

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