0

I'm running a jenkins container in EKS and everything is working fine except when one of the pipelines has to build docker images.

I've installed docker cli on my image but when i shell into the jenkins pod and run docker ps or docker version, i get the following error:

jenkins@b8b3fe3f061d:/$ docker ps
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
jenkins@b8b3fe3f061d:/$ docker version
Client:
 Version:           18.09.2
 API version:       1.39
 Go version:        go1.10.6
 Git commit:        6247962
 Built:             Sun Feb 10 04:13:52 2019
 OS/Arch:           linux/amd64
 Experimental:      false
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

My Dockerfile is below:

FROM jenkins/jenkins:2.440.1-lts
# Pipelines with Blue Ocean UI and Kubernetes
ARG DOCKER_GID=999
RUN jenkins-plugin-cli --plugins blueocean kubernetes
USER root
COPY java-17-amazon-corretto-jdk_17.0.8.8-1_amd64.deb ./
RUN apt-get update && apt-get install -y curl vim zip unzip java-common wget libltdl7 \
    && dpkg --install java-17-amazon-corretto-jdk_17.0.8.8-1_amd64.deb \
    && rm /bin/sh && ln -s /bin/bash /bin/sh

USER jenkins
RUN curl -s https://get.sdkman.io | bash \
    && chmod a+x "$HOME/.sdkman/bin/sdkman-init.sh" \
    && source "$HOME/.sdkman/bin/sdkman-init.sh"

ENV JAVA_HOME=/usr/lib/jvm/java-17-amazon-corretto/
ENV PATH=/usr/lib/jvm/java-17-amazon-corretto/:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
RUN mkdir -p /var/jenkins_home/.ssh \
    && mkdir -p /var/jenkins_home/.gradle \
    && mkdir -p /var/jenkins_home/.aws \
    && chmod 0700 /var/jenkins_home/.ssh \
    && chmod -R 755 /var/jenkins_home \
    && chown -R 1000:1000 /var/jenkins_home 
ADD id_rsa /var/jenkins_home/.ssh/
ADD credentials /var/jenkins_home/.aws
ADD known_hosts /var/jenkins_home/.ssh/
ADD gradle.properties /var/jenkins_home/.gradle/

USER root
EXPOSE 22
RUN chmod -R 0700 /var/jenkins_home/.ssh \
    && chmod 0600 /var/jenkins_home/.ssh/id_rsa \
    && chmod 0600 /var/jenkins_home/.ssh/known_hosts \
    && chmod 644 /var/jenkins_home/.aws/credentials
# Install Docker
RUN wget -q -O /tmp/docker-cli.deb https://download.docker.com/linux/debian/dists/stretch/pool/stable/amd64/docker-ce-cli_18.09.2~3-0~debian-stretch_amd64.deb \
    && dpkg -i /tmp/docker-cli.deb

# create docker group, add jenkins user to it
RUN groupadd -g $DOCKER_GID docker \
    && usermod -aG docker jenkins

USER jenkins
2
  • I'm not familiar with EKS, but the root issue is the container cannot access the host machine's docker socket. When containerized Jenkins runs a docker command, it's actually communicating with the host machine's docker daemon. How was the Jenkins container started? Do you have control over the volume mounts?
    – jpiddle888
    Commented May 15 at 2:40
  • It works on my minikube cluster but when i try the same on EC2, it doesn't work. I do have volume mounted in the container from EC2. volume { name = "dockersock" host_path { path = "/var/run/docker.sock" type = "Socket" } } volume_mount { name = "dockersock" mount_path = "/var/run/docker.sock" } Commented May 16 at 20:34

0

You must log in to answer this question.

Browse other questions tagged .