I am trying to run docker inside an Ubuntu docker container to use it as a docker build agent for Jenkins.
I am getting the following error when I try to run the docker build command to create a docker image.
Error in Jenkins
ERROR: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
Docker file for Docker build agent
FROM ubuntu:latest
RUN apt update
USER root
RUN apt install -y git
RUN apt-get install \
ca-certificates \
curl \
gnupg -y
RUN mkdir -m 0755 -p /etc/apt/keyrings
RUN curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg
RUN echo \
"deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
"$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \
tee /etc/apt/sources.list.d/docker.list > /dev/null
RUN apt-get update
RUN apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin -y
RUN curl -fsSL https://deb.nodesource.com/setup_19.x | bash - &&\
apt-get install -y nodejs
The pipeline is supposed to :
- clone a repository
- build the react app
- build a Docker image and push it to docker registry.
How can I get this setup running ? Or is there a better approach in achieving this ?
I have to use a docker build agent as the all the tools necessary are not always directly install in the host machine.