Skip to content
Advertisement

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?

Advertisement

Answer

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:

job on gitlab.com

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement