skip to Main Content

Ive created a Dockerfile that is based off jenkins/jenkins:lts-jdk11

Im trying to install docker + docker compose so that jenkins will have access to this when i create my pipeline for CD/CI.

Here is my Dockerfile:

FROM jenkins/jenkins:lts-jdk11 AS jenkins

WORKDIR /home/jenkins

RUN chown -R 1000:1000 /var/jenkins_home

USER root

# Install aws cli version 2
RUN apt-get update && apt-get install -y unzip curl vim bash sudo
RUN curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
RUN unzip awscliv2.zip
RUN ./aws/install

#Install docker cli command
RUN sudo apt-get update
RUN sudo apt install -y apt-transport-https ca-certificates curl gnupg lsb-release
RUN curl -fsSL https://download.docker.com/linux/debian/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
RUN echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/debian 
      $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
RUN sudo apt-get update
RUN sudo apt-get install -y docker-ce docker-ce-cli containerd.io

##Install docker compose
RUN mkdir -p /usr/local/lib/docker/cli-plugins
RUN curl -SL https://github.com/docker/compose/releases/download/v2.2.3/docker-compose-linux-x86_64 -o /usr/local/lib/docker/cli-plugins/docker-compose
RUN chmod +x /usr/local/lib/docker/cli-plugins/docker-compose

RUN sudo usermod -a -G docker jenkins

The docker commands work well within the container but as soon as i start to build an image it displays this error:

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

If i try to start the docker service with service docker start i get the following error:

mkdir: cannot create directory ‘cpuset’: Read-only file system

Im not sure how to solve this one.

TIA

2

Answers


  1. container does not use an init system. The Docker service cannot be started because of this.

    Login or Signup to reply.
  2. I had the same issue while trying to run docker inside the Jenkins container using ECS Fargate.

    TLDR: Fargate doesn’t support privileged containers. So you need to switch to EC2 to be able to run docker.

    I used the following setup:

    FROM jenkins/jenkins:lts-jdk11
    USER root
    
    # Install Docker and Docker Compose
    RUN apt-get update
    RUN apt-get install -y apt-transport-https 
                           ca-certificates 
                           curl 
                           gnupg-agent 
                           software-properties-common && 
        curl -fsSL https://download.docker.com/linux/debian/gpg | apt-key add - && 
        add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/debian $(lsb_release -cs) stable"
    RUN apt-get update && 
        apt-get install -y docker-ce docker-ce-cli containerd.io && 
        curl -L https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose && 
        chmod +x /usr/local/bin/docker-compose
    
    # Install necessary plugins for Jenkins
    RUN jenkins-plugin-cli --plugins 
            docker-workflow 
            blueocean 
            pipeline-utility-steps 
            cloudbees-folder
    
    # Setup Debian to use the legacy iptables instead of nftables
    RUN  update-alternatives --set iptables /usr/sbin/iptables-legacy && 
         update-alternatives --set ip6tables /usr/sbin/ip6tables-legacy
    
    # Expose ports for Jenkins
    EXPOSE 8080
    

    Container should be launched with the following command:

    docker run --privileged -p 8080:8080 -v jenkins_home:/var/jenkins_home myjenkins 
    

    Before running any docker command use service docker start command to start docker.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search