Table of Contents

Jenkins

https://github.com/jenkinsci/docker

https://itnext.io/docker-inside-docker-for-jenkins-d906b7b5f527

Install in docker environment:

docker run -p 8080:8080 -p 50000:50000 --restart=always -d -v /var/run/docker.sock:/var/run/docker.sock -v /data/jenkins/:/var/jenkins_home --name=jenkins-master jenkins/jenkins:lts

or

docker run -v /var/run/docker.sock:/var/run/docker.sock -v /data/jenkins:/var/jenkins_home -p 8443:8443 jenkins --httpPort=-1 --httpsPort=8443 --httpsKeyStore=/var/jenkins_home/jenkins_keystore.jks --httpsKeyStorePassword=

Dockerfile

Building jenkins with https to run docker and docker-compose inside jenkins:

FROM jenkins/jenkins:lts

LABEL version="1.0"
LABEL maintainer="tmade"

ENV JENKINS_OPTS="--handlerCountMax=300 --logfile=/var/log/jenkins/jenkins.log"
ENV JENKINS_OPTS --httpPort=8080 --httpsPort=8443 --httpsKeyStore=/var/lib/jenkins/jenkins.local.jks --httpsKeyStorePassword=<secret>
#ENV JAVA_OPTS="-Xmx8192m"
#ENV COMPOSE-VERSION="1.27.4"

USER root
RUN apt-get -y update && \
 apt-get -y install apt-transport-https ca-certificates curl gnupg-agent software-properties-common && \
 curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add - && \
 add-apt-repository \
 "deb [arch=amd64] https://download.docker.com/linux/$(. /etc/os-release; echo "$ID") \
 $(lsb_release -cs) \
 stable" && \
 apt-get update && \
 apt-get install -y net-tools && \
 apt-get -y install docker-ce docker-ce-cli containerd.io

RUN mkdir /var/log/jenkins
RUN chown -R  jenkins:jenkins /var/log/jenkins
RUN usermod -aG docker jenkins

RUN curl -L "https://github.com/docker/compose/releases/download/${COMPOSE-VERSION}/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose && \
 chmod +x /usr/local/bin/docker-compose && \
 ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose

#RUN echo "jenkins ALL=NOPASSWD: ALL" >> /etc/sudoers

RUN mkdir /var/lib/jenkins
COPY jenkins.local.jks /var/lib/jenkins/jenkins.local.jks
RUN chown -R jenkins:jenkins /var/lib/jenkins

USER jenkins

docker-compose

version: '2'

services:
  jenkins:
    image: myjenkins:lts
    #image: jenkins/jenkins:lts
    #user: "1000:1000"
    #user: "${UID}:${GID}"
    container_name: jenkins-master
    ports:
      - 8888:8080
      - 50000:50000
      - 8443:8443
    volumes:
      - /data/jenkins/:/var/jenkins_home
      - /var/run/docker.sock:/var/run/docker.sock
      - /data/jenkins/logs/:/var/log/jenkins
    restart: always
    #restart: unless-stopped

Permission-Problems:

usermod -aG docker jenkins
sudo service docker restart