为gitlab ci社区版启用docker

时间:2016-08-04 20:14:22

标签: docker sbt gitlab gitlab-ci gitlab-ci-runner

我在为生成作业启用docker时遇到了困难。这就是gitlab ci配置文件的样子:

image: docker:latest

services:
  - docker:dind

stages:
  - build

build:
  image: java:8
  stage: build
  script:
    - docker info
    - docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN registry.gitlab.com/...
    - sbt server/docker:publish

这是作业的输出:

gitlab-ci-multi-runner 1.3.2 (0323456)
Using Docker executor with image java:8 ...
Pulling docker image docker:dind ...
Starting service docker:dind ...
Waiting for services to be up and running...
Pulling docker image java:8 ...
Running on runner-30dcea4b-project-1408237-concurrent-0 via runner-30dcea4b-machine-1470340415-c2bbfc45-digital-ocean-4gb...
Cloning repository...
Cloning into '/builds/.../...'...
Checking out 9ba87ff0 as master...
$ docker info
/bin/bash: line 42: docker: command not found

ERROR: Build failed: exit code 1    

为什么找不到码头工人的任何线索?

2 个答案:

答案 0 :(得分:2)

经过几天的挣扎,我想出了以下设置:

image: gitlab/dind

stages:
  - test
  - build

before_script:
 - echo oracle-java8-installer shared/accepted-oracle-license-v1-1 select true | debconf-set-selections
 - apt-get update
 - apt-get install -y curl
 - apt-get install -y software-properties-common python-software-properties
 - add-apt-repository -y ppa:webupd8team/java
 - apt-get update
 - apt-get install -y oracle-java8-installer
 - rm -rf /var/lib/apt/lists/*
 - rm -rf /var/cache/oracle-jdk8-installer
 - apt-get update -yqq
 - apt-get install apt-transport-https -yqq
 - echo "deb http://dl.bintray.com/sbt/debian /" | tee -a /etc/apt/sources.list.d/sbt.list
 - apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 642AC823
 - apt-get update -yqq
 - apt-get install sbt -yqq
 - sbt sbt-version

test:
  stage: test
  script:
    - sbt scalastyle && sbt test:scalastyle
    - sbt clean coverage test coverageReport

build:
  stage: build
  script:
    - docker info
    - docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN registry.gitlab.com/...
    - sbt server/docker:publish

它有docker(mind gitlab/dind image),java和sbt。现在我可以从sbt docker插件推送到gitlab注册表。

答案 1 :(得分:1)

docker info命令在基于java:8的容器内运行,该容器中没有安装/可用的docker。