2

I'm trying to establish a Jenkins Pipeline, that's able to build docker images. But I ran into the problem docker: not found after executing the pipeline. The Jenkinsfile has the following content:

pipeline {
    agent { dockerfile true }
    stages {
        stage('Test') {
            steps {
                sh 'docker --version '
            }
        }
    }
}

It's a simple script to get things started. But it seems that the dockerized Jenkins installation can't find a suitable docker installation to use. The required plugins (Docker and Docker pipeline) are installed and a global docker installation configuration is present. But the error keeps going.

Jenkins setup is done by using this docker-compose:

version: '3.1'

networks:
  docker:

volumes:
  jenkins-data:
  jenkins-docker-certs:

services:

  jenkins:
    image: jenkins/jenkins:lts
    restart: always
    networks:
      - docker
    ports:
      - 8090:8080
      - 50000:50000
    tty: true
    volumes:
      - jenkins-data:/var/jenkins_home
      - jenkins-docker-certs:/certs/client:ro
      - $HOME:/home
    environment:
      - DOCKER_HOST=tcp://docker:2376
      - DOCKER_CERT_PATH=/certs/client
      - DOCKER_TLS_VERIFY=1

  dind:
    image: docker:dind
    privileged: true
    restart: always
    networks:
      docker:
        aliases:
          - docker
    ports:
      - 2376:2376
    tty: true
    volumes:
      - jenkins-data:/var/jenkins_home
      - jenkins-docker-certs:/certs/client
      - $HOME:/home
    environment:
      - DOCKER_TLS_CERTDIR=/certs

After reading some more posts about that issue and following the official Jenkins doc, I thought that for this purpose docker:dind is used. Maybe I miss some important configurations here? When launching the docker:dind container, the log states the following warning message: could not change group /var/run/docker.sock to docker: group docker not found, but the group exists and I'm able to run docker commands without specifying sudo. (Followed the official docker post-installation steps)

Another problematic point right now is, that Jenkins can't persist configuration data in general or pipeline related stuff. After restarting the machine I have to go through the wizard every single time and I don't know why.

Did someone suffer similar problems?

Many thanks in advice!

andreas.teich
  • 789
  • 1
  • 12
  • 22

2 Answers2

2

Your docker-compose file is correct, you just need to add a volume in the jenkins container :

- /usr/bin/docker:/usr/bin/docker

You have also a lot of configuration not required, you can check this link to see others possible configurations. You use actually the Solution 3 and you can switch to this docker-compose file.

For volumes, they should be persisted since they are declared in the volume section. You can try to use external volumes if needed.

fmdaboville
  • 1,394
  • 3
  • 15
  • 28
  • 3
    Indeed, many thanks for that great article, fixed the originated problem that docker can't be found. Suffering another problem now: `docker: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.32' not found (required by docker)`. The host's `GLIBC` version is `ldd (Ubuntu GLIBC 2.33-0ubuntu5) 2.33` what's going on here? – andreas.teich Sep 02 '21 at 14:48
  • where do you get this ? – fmdaboville Sep 02 '21 at 14:51
  • Within my pipeline script. `+ docker inspect -f . node:14-alpine docker: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.32' not found (required by docker)` and a few lines below `+ docker pull node:14-alpine docker: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.32' not found (required by docker)` – andreas.teich Sep 02 '21 at 15:24
  • I don't really know, but I'v found some explications about it : https://stackoverflow.com/a/52827558/7953086 it seems that you need to found aother version – fmdaboville Sep 02 '21 at 22:19
0

Fast forward one year and I've run into analogous problem, only with mismatched GLIBC versions, as described here.

I solved it by upgrading GLIBC version in the Jenkins container to 2.35 (as shipped with Ubuntu Jammy on the host). To achieve this I had to build my own Jenkins container based on ubuntu:jammy and JDK 17, using a template from the official Debian-based one (sourced from here). Now GLIBC versions agree, and docker-in-docker Jenkins builds can be made using docker installed on a host with Ubuntu Jammy:

$ ldd --version
ldd (Ubuntu GLIBC 2.35-0ubuntu3.1) 2.35

# vs.

$ docker run --rm -it mirekphd/jenkins-jdk17-on-ubuntu-2204:2.374 ldd --version
ldd (Ubuntu GLIBC 2.35-0ubuntu3.1) 2.35

Feel free to use this container (best served with the latest tag), as I will have to maintain it for our own in-house use, setting its builds as one of... Jenkins pipelines (bootstrap problem notwithstanding). It will be a Docker-in-Docker Jenkins-in-Jenkins pipeline:)

mirekphd
  • 4,799
  • 3
  • 38
  • 59