I am running following commands:
docker run --name myjenkins -u root -d -p 8080:8080 -p 50000:50000 -v jenkins-data:/var/jenkins_home -v /var/run/docker.sock:/var/run/docker.sock --privileged vaish
docker exec -it myjenkins vaish
service docker start
service docker status
output is [FAIL] Docker is not running ... failed!
Note: I have installed docker via dockerfile Note: my application is a set of docker containers
when i check service docker status on my host machine it is active(running )but the problem is from inside container!
Dockerfile:
FROM jenkins/jenkins:lts
ENV JENKINS_SLAVE_AGENT_PORT '50000'
USER $USER
WORKDIR /var/jenkins_home/workspace/pipelineDemo@script
ARG NODE_ENV
ENV NODE_ENV=$NODE_ENV
RUN apt-get update
RUN curl -sL https://deb.nodesource.com/setup_9.x | bash -
RUN apt-get install -y nodejs
RUN apt-get update
RUN apt-get install -y npm
RUN npm install -g npm
RUN apt-get install python3
RUN apt-get install --reinstall make
RUN npm install --global gulp-cli
RUN npm install --global gulp
RUN apt-get -y install g++
RUN apt-get update
RUN apt-get install
RUN apt-get -y install apt-transport-https \
ca-certificates \
curl \
gnupg2 \
software-properties-common
RUN curl -fsSL https://download.docker.com/linux/debian/gpg | apt-key add -
RUN apt-key fingerprint 0EBFCD88
RUN add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/debian \
$(lsb_release -cs) \
stable"
RUN apt-get update
RUN apt-get install -y docker-ce
RUN curl -L https://github.com/docker/compose/releases/download/1.21.2/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose
RUN chmod +x /usr/local/bin/docker-compose
RUN usermod -aG docker jenkins
USER jenkins
COPY Jenkinsfile /var/jenkins_home/workspace/pipelineDemo@script
CMD [ "npm", "start" ]
when i dont have docker in my jenkins docker container and i run npm run install I get following logs: in order ro avoid these error i had to install docker and docker compose in my jenkins docker container
> /var/jenkins_home/workspace/pipelineDemo@script
> node tasks/down.js
✖ Command failed: docker-compose kill
/bin/sh: 1: docker-compose: not found
>/var/jenkins_home/workspace/pipelineDemo@script
> node tasks/build.js
✔ bundle admin
✔ bundle front-end
✖ build admin
→ /bin/sh: 1: docker: not found
✖ build bank-accounts
→ /bin/sh: 1: docker: not found
Note: on my host machine docker got installed with npm i and npm run install commands
I had the same issue. I found a solution here:
When you start your Jenkins container use -v to hand the host's docker.sock to the container:
docker run -v /var/run/docker.sock:/var/run/docker.sock ...
It might also be an issue that you run an root, while Jenkins is being run by user jenkins. I'd expect a different error though.
Here is my Jenkinsfile (I don't install docker-compose)
FROM jenkins/jenkins
USER root
RUN apt update && apt install -y apt-transport-https ca-certificates curl gnupg2 software-properties-common
RUN curl -fsSL https://download.docker.com/linux/debian/gpg | apt-key add -
RUN apt-key fingerprint 0EBFCD88
RUN add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/debian $(lsb_release -cs) stable"
RUN apt update && apt install -y docker-ce
RUN usermod -aG docker jenkins
USER jenkins
I start the container with
docker run --name mycustomjenkins \
-p 8080:8080 -p 50000:50000 \
-v jenkins_home:/var/jenkins_home \
-v /var/run/docker.sock:/var/run/docker.sock <IMAGE-ID>
That way I am able to use Docker agents in my Jenkins.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With