7

I have java project which using testcontainers for integration test. I want to implement gitlab ci for that stage but I've got that error

java.lang.IllegalStateException: Could not find a valid Docker environment. Please see logs and check configuration

The project build successfully on local machine but gitlap ci docker couldn't start propeply

Here a log output


[0KRunning with gitlab-runner 14.3.0 (b37d3da9)[0;m
[0K  on Backend Docker runner 9L3Zko1w[0;m
section_start:1657698628:prepare_executor
[0K[0K[36;1mPreparing the "docker" executor[0;m[0;m
[0KUsing Docker executor with image maven:3.6.0-jdk-11-slim ...[0;m
[0KStarting service docker:dind ...[0;m
[0KPulling docker image docker:dind ...[0;m
[0KUsing docker image sha256:232342342342 for docker:dind with digest docker@sha256:2342342342 ...[0;m
[0KWaiting for services to be up and running...[0;m

[0;33m*** WARNING:[0;m Service runner-23423423-docker-0 probably didn't start properly.

Health check error:
service "runner-234234234-docker-0-wait-for-service" timeout

Health check container logs:


Service container logs:
2022-07-13T07:50:40.800780292Z ip: can't find device 'ip_tables'
2022-07-13T07:50:40.801898214Z ip_tables              32768  2 iptable_filter,iptable_nat
2022-07-13T07:50:40.802546323Z x_tables               45056  5 xt_conntrack,xt_MASQUERADE,xt_addrtype,iptable_filter,ip_tables
2022-07-13T07:50:40.802609399Z modprobe: can't change directory to '/lib/modules': No such file or directory
2022-07-13T07:50:40.806461330Z mount: permission denied (are you root?)
2022-07-13T07:50:40.807019652Z Could not mount /sys/kernel/security.
2022-07-13T07:50:40.807028026Z AppArmor detection and --privileged mode might break.
2022-07-13T07:50:40.807931221Z mount: permission denied (are you root?)

here is gitlab ci yaml

services:
  - name: docker:dind
    # explicitly disable tls to avoid docker startup interruption
    command: ["--tls=false"]
variables:
  # Instruct Testcontainers to use the daemon of DinD.
  DOCKER_HOST: "tcp://docker:2375"
  # Instruct Docker not to start over TLS.
  DOCKER_TLS_CERTDIR: ""
  # Improve performance with overlayfs.
  DOCKER_DRIVER: overlay2
test:
  image: maven:3.8.6-jdk-11-slim
  stage: ⚙️ maven-build
  before_script:
    - docker info
    - cp $MAVEN_SETTINGS_XML ~/.m2/settings.xml
  script:
    - mvn $MAVEN_CLI_OPTS clean verify



neoerol
  • 911
  • 1
  • 12
  • 18

1 Answers1

1

Just using the maven:3.8.6-jdk-11-slim image is not enough. You also need docker installed in your image. A very easy way to get docker is by just installing it manually in your pipeline:

before_script:
    - curl -fsSL https://get.docker.com -o get-docker.sh
    - bash ./get-docker.sh
    - docker info

However, it would be much better if you installed docker in a custom docker image so that you aren't constantly installing docker on every pipeline run. You can do that with this dockerfile:

FROM maven:3.8.6-jdk-11-slim
RUN curl -fsSL https://get.docker.com -o get-docker.sh
RUN bash ./get-docker.sh

The resulting image can then be uploaded to a registry and used instead of maven:3.8.6-jdk-11-slim without needing to install docker each time.

R10t--
  • 803
  • 7
  • 16
  • 2
    You don't need Docker installed when using Testcontainers and having the `dind` service attached should normally be sufficient. – Kevin Wittek Jul 13 '22 at 13:29
  • I've never been able to run docker commands with the dind service unless my base image also had docker installed – R10t-- Jul 14 '22 at 19:51
  • 1
    For `docker CLI` commands this is correct. However, Testcontainers interacts with the Docker daemon over the Docker REST API. But you are right, the example above contains a call to `docker info`, which would require the CLI to be present. – Kevin Wittek Jul 15 '22 at 08:00
  • 1
    This is still the only alternative ? I mean, the only way is to have an image with both docker and maven? – lubrum Jan 18 '23 at 02:12
  • 1
    Any solution? I'm running into the same issue, and I'm not sure what's the correct approach – rogger2016 Feb 16 '23 at 11:32