简体   繁体   中英

Gitlab-ci docker inside java image

To use a integration test library https://www.testcontainers.org/" I need a image with java a docker installed at same time.

I'm trying o use this stage:

test:
  stage: test
  image: gradle:jdk16
  services:
    - docker:latest
  script:
    - docker --version
    - chmod +x ./gradlew
    - export GRADLE_USER_HOME=`pwd`/.gradle
    - ./gradlew test  --stacktrace
  rules:
    - !reference [.rules_merge_request, rules]

But It does not work:

$ docker --version
/scripts-33119345-2089057982/step_script: line 154: docker: command not found

Any help?

The image gradle:jdk16 does not include the docker client. You'll have to install it in your job. Additionally, you'll need to use the service docker:dind in your services: configuration (not docker:latest )

test:
  stage: test
  image: gradle:jdk16
  services:
    - docker:dind # use the docker-in-docker image
  before_script: # install docker
    - apt update && apt install --no-install-recommends -y docker.io  
  script:
    - docker --version

Running this on gitlab.com runners, you should see an output like this:

在 gitlab.com 上工作

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM