Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jenkins in Docker container (run docker pipeline)

Tags:

docker

jenkins

I want to run Jenkins in Docker container. Everything is OK. I can run it like this: docker run -d --name jenkins -t -i -p 49001:8080 jenkins I can also add persistent storage. The problem came when I created a pipeline can has to execute docker commands (build and push). First the error was that docker wasn't installed on the system. Yes, expected. Then I started searching and found out how I can run docker in container (passing 2 persistent volumes): docker run ... -v /var/run/docker.sock:/var/run/docker.sock -v $(which docker):/usr/bin/docker -p 49001:8080 jenkins

This runs, but with some exceptions. There is docker command in the container but when I try to run it, it throws an exception: docker: error while loading shared libraries: libltdl.so.7: cannot open shared object file: No such file or directory

How can I fix this problem? What is the correct way for installing Jenkins in Docker and run Docker in it? I think there are 2 ways:

  1. The one that I am doing - use the sockets
  2. I can expose the docker api that allows connections and running commands

Actually is it worth running Jenkins in Docker? I tried to install the missing lib manually from the apt-get It works but I know that it's not the correct way..

like image 305
Kiril Stoyanov Avatar asked Jul 15 '17 19:07

Kiril Stoyanov


People also ask

Can Jenkins run Docker container?

Just use a pre-configured Docker container and your Jenkins builds get access to all of those resources, without the headache of managing and maintaining all of that peripheral software.

How do I run Docker in a Docker container?

To run docker inside docker, all you have to do it just run docker with the default Unix socket docker. sock as a volume. Just a word of caution: If your container gets access to docker. sock , it means it has more privileges over your docker daemon.

Can we use Docker container as a node in Jenkinsfile?

Docker plugin for Jenkins The aim of this docker plugin is to be able to use a Docker host to dynamically provision a docker container as a Jenkins agent node, let that run a single build, then tear-down that node, without the build process (or Jenkins job definition) requiring any awareness of docker.


1 Answers

You have to install libltdl-dev in order to get everything working correctly. Create a Dockerfile that looks like this:

FROM jenkins:latest

USER root
RUN apt-get update \
      && apt-get upgrade -y \
      && apt-get install -y sudo libltdl-dev \
      && rm -rf /var/lib/apt/lists/*
RUN echo "jenkins ALL=NOPASSWD: ALL" >> /etc/sudoers

USER jenkins
# Here you can install some Jenkins plugins if you want
like image 82
kirpt Avatar answered Sep 25 '22 19:09

kirpt