Jenkins Container - Docker installation - docker daemon not working

1/7/2022

I am trying to install Docker within Jenkins docker container.

Here is my Dockerfile.

from jenkinsci/jenkins:lts

USER root
RUN apt-get update -qq \
    && apt-get install -qqy apt-transport-https ca-certificates curl gnupg2 software-properties-common
RUN curl -fsSL https://download.docker.com/linux/debian/gpg | apt-key add -
RUN add-apt-repository \
   "deb [arch=amd64] https://download.docker.com/linux/debian \
   $(lsb_release -cs) \
   stable"
RUN apt-get update  -qq \
    && apt-get install docker-ce=17.12.1~ce-0~debian -y
RUN usermod -aG docker jenkins && docker images

As I am mentioning firing the command docker images and here it throws error

Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

Any suggestion how make Docker run ?

(not important, FYI): Finally I am running it from kubernetes which works fine without Docker but I need the docker images to be build from jenkins ci, hence it is needed.

Jenkins yaml:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: jenkins
  labels:
    app: jenkins
spec:
  selector:
    matchLabels:
      app: jenkins
  replicas: 1
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 0
  template:
    metadata:
      labels:
        app: jenkins
    spec:
      serviceAccountName: jenkins
      containers:
      - name: jenkins
        image: europe-west1-docker.pkg.dev/xxx/xxxxx-custom-jenkins/jenkins:v5 
        imagePullPolicy: IfNotPresent
        env:
        - name: JAVA_OPTS
          value: -Xmx2048m -Dhudson.slaves.NodeProvisioner.MARGIN=50 -Dhudson.slaves.NodeProvisioner.MARGIN0=0.85
        ports:
        - containerPort: 8080
          protocol: TCP
        - containerPort: 50000
          protocol: TCP
        volumeMounts:
        - mountPath: /var/jenkins_home
          name: jenkins
      restartPolicy: Always
      securityContext:
        runAsUser: 0
      terminationGracePeriodSeconds: 30
      volumes:
      - name: jenkins
        persistentVolumeClaim:
          claimName: pvc-jenkins
-- ARINDAM BANERJEE
docker
jenkins
kubernetes

0 Answers