簡體   English   中英

如何在Gitlab CI / CD中啟動Docker容器

[英]How to launch a Docker container in Gitlab CI/CD

我是Gitlab的新手(而且我只知道git的基本功能:pull,push,merge,branch ...)。

我正在使用通過docker docker run -p 8000:8000 amazon/dynamodb-local啟動的本地DynamoDB數據庫對我的Python項目進行單元測試。 因此,我必須在Gitlab CI / CD中啟動此docker容器,以便我的單元測試正常工作。

我已經在gitlab網站上閱讀了有關此主題的文檔,但未找到問題的答案,並且我知道我必須修改gitlab-ci.yml文件才能啟動gitlab-ci.yml容器。

使用Gitlab時,可以使用Docker-in-Docker。

在.gitlab-ci.yml文件的頂部

image: docker:stable

services:
- docker:dind

然后,在測試階段,您可以啟動數據庫並使用它。

unit_tests:
  stage: tests
  script:
  - export CONTAINER_ID=$(docker run -p 8000:8000 amazon/dynamodb-local)
  ## You might need to wait a few seconds with `sleep X` for the container to start up.
  ## Your database is now here docker:8000
  ## Run your tests here. Database host=docker and port=8000

這是我發現的最好方法,也是最容易理解的方法

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM