使用Docker从Travis迁移到GitLab CI

时间:2019-10-02 12:56:58

标签: docker gitlab-ci-runner

我正在从Travis迁移到GitLab CI,并且正在努力使Docker工作:

.gitlab-ci.yml文件:

image: docker:latest

services:
  - docker-dind

stages:
  - build
  - test

before_script:
  - apk add python3 python3-dev python3-pip
  - pip3 install --upgrade pip
  - pip3 install --no-cache-dir docker-compose
  - export REACT_APP_USERS_SERVICE_URL=http://127.0.0.1


compile:
  stage: build
  script:
    - docker-compose up --build -d


test:
  stage: test
  script:
    - docker-compose exec users python manage.py test

after_script:
  - docker-compose down

生成错误抛出:

ERROR: Job failed: Error response from daemon: pull access denied for docker-dind, repository does not exist or may require 'docker login' (executor_docker.go:188:0s)

如何解决此问题?到目前为止,我不需要docker登录。

编辑: 在研究了GitLab文档以及类似的SO主题之后,我想到了:

image: docker:stable

services:
  - docker:dind

stages:
  - build
  - test

before_script:
  - apk add python python-dev python-pip
  - pip install --no-cache-dir docker-compose
  - export REACT_APP_USERS_SERVICE_URL=http://127.0.0.1

compile:
  stage: build
  script:
    - docker-compose up --build -d


test:
  stage: test
  script:
    - docker-compose exec users python manage.py test

after_script:
  - docker-compose down

错误输出为:

fetch http://dl-cdn.alpinelinux.org/alpine/v3.10/community/x86_64/APKINDEX.tar.gz
ERROR: unsatisfiable constraints:
  pip (missing):
    required by: world[pip]

2 个答案:

答案 0 :(得分:0)

它是docker:dind,而不是docker-dind

services:
  - docker:dind

答案 1 :(得分:0)

这是运行它的.gitlab-ci.yml文件:

image: docker:stable

services:
  - docker:dind

stages:
  - build
  - test

before_script:
  - apk add --no-cache py-pip python-dev libffi-dev openssl-dev gcc libc-dev make
  - pip install --no-cache-dir docker-compose
  - export REACT_APP_USERS_SERVICE_URL=http://127.0.0.1

compile:
  stage: build
  script:
    - docker-compose up --build -d


test:
  stage: test
  script:
    - docker-compose exec users python manage.py test

after_script:
  - docker-compose down