Practical notes on installing Jenkins with docker-compose

Practical notes on installing Jenkins with docker-compose

Create a Directory

cd /usr/local/docker/
mkdir jenkins-docker
cd jenkins-docker

Create Dockerfile

vi Dockerfile
# The following is the file content FROM jenkins/jenkins:lts

USER root
RUN mkdir -p /usr/local/ && \
	cd /usr/local/ && \
	curl -fsSL https://mirror.bit.edu.cn/apache/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz > /usr/local/apache-maven-3.6.3-bin.tar.gz && \
	tar xzf /usr/local/apache-maven-3.6.3-bin.tar.gz -C /usr/local/ && \
	rm -rf /usr/local/apache-maven-3.6.3-bin.tar.gz && \
	ln -s /usr/local/apache-maven-3.6.3/bin/mvn /bin/mvn && \
	ln -s /usr/local/apache-maven-3.6.3/bin/mvnyjp /bin/mvnyjp && \
	export PATH=/usr/local/apache-maven-3.6.3/bin:$PATH

USER jenkins

Build the image

docker build -t jenkins-jiacs:lts .

View Docker's Group ID on the host

cat /etc/group | grep docker

# [root@localhost jenkins-docker]# cat /etc/group | grep docker
# docker:x:994:
# My value is 994, depending on the actual value

Start the Jenkins container (start with the docker command line)

# Before starting the container, create the /usr/local/docker/jenkins-docker/data folder and grant permissions # /usr/local/docker/jenkins-docker/config/settings.xml This file is provided by itself (private server and other information can be customized)
mkdir data
chmod -R 777 data

docker run -d -p 8080:8080 -p 50000:50000 \
    -v /usr/local/docker/jenkins-docker/data:/var/jenkins_home \
    -v /etc/localtime:/etc/localtime:ro \
    -v /var/run/docker.sock:/var/run/docker.sock \
    -v /etc/docker:/etc/docker \
    -v /usr/bin/docker:/usr/bin/docker \
    -v /usr/local/bin/docker-compose:/usr/local/bin/docker-compose \
    -v /usr/local/docker/jenkins-docker/config/settings.xml:/usr/local/apache-maven-3.6.3/conf/settings.xml \
    --group-add=994 \
    --name my-jenkins \
    jenkins-jiacs:lts
# illustrate:
# 1. -v /usr/local/docker/jenkins-docker/data:/var/jenkins_home =》Persist Jenkins data# 2. -v /etc/localtime:/etc/localtime:ro =》Set the Jenkins container time to be consistent with the host# 3. -v /etc/docker:/etc/docker =》The docker used in the Jenkins container is the docker installed on the host, ensuring that the service deployed by Jenkins is started in the host# 4. -v /usr/local/bin/docker-compose:/usr/local/bin/docker-compose If the host has docker-compose installed, you can add the data volume if the Jenkins container needs to use it# -v /usr/local/docker/jenkins-docker/config/settings.xml:/usr/local/apache-maven-3.6.3/conf/settings.xml
# --group-add=994 Set the user group of the started container to the user group of docker in the host machine, ensuring that the Jenkins container has the authority to operate the docker command of the host machine

Start the Jenkins container (docker-compose start)

cd /usr/local/docker/jenkins-docker
vi jenkins-docker.yaml
version: '2' # Do not modify the version number, some versions do not support the group_add parameter services:
  Jenkins:
    image: 'jenkins-jiacs:lts'
    container_name: my-jenkins
    # restart: always
    ports:
      - '8080:8080'
      - '50000:50000'
    group_add:
      - 994
    volumes:
      - ./data:/var/jenkins_home
      - /etc/localtime:/etc/localtime:ro
      - /var/run/docker.sock:/var/run/docker.sock
      - /etc/docker:/etc/docker
      - /usr/bin/docker:/usr/bin/docker
      - /usr/local/bin/docker-compose:/usr/local/bin/docker-compose
      - ./config/settings.xml:/usr/local/apache-maven-3.6.3/conf/settings.xml

start up

docker-compose -f jenkins-docker.yaml up -d

View Container

docker ps 

insert image description here

Entering the container

docker exec -it 0d8b70ba5cec bash
# View the Jenkins initial password (executed in the container)
cat /var/jenkins_home/secrets/initialAdminPassword

Open the browser and access the Jenkins service

http://<host IP>:8080/

Fill in the initial password you just found

insert image description here

Select the recommended plugins to install and wait for the plugins to be installed (it will take a little longer). If some plugins fail to install, you can click Retry to continue the installation, or record the failed plugins and manually install them in System Configuration - Plugin Configuration.

insert image description here

Change Jenkins time zone

System Management > Script Command Line, enter the following command and click [Run]

System.setProperty('org.apache.commons.jelly.tags.fmt.timeZone', 'Asia/Shanghai')

Installation Complete

This is the end of this article about installing Jenkins with docker-compose. For more information about installing Jenkins with docker-compose, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Detailed process of installing Jenkins-2.249.3-1.1 with Docker
  • A detailed tutorial on how to install Jenkins on Docker for beginners
  • How to install Jenkins using Docker
  • Detailed tutorial on installing the jenkins container in a docker environment
  • Install Jenkins with Docker and solve the problem of initial plugin installation failure
  • Sample code for installing Jenkins using Docker
  • Docker deployment and installation steps for Jenkins

<<:  Pure CSS3 to achieve mouse over button animation Part 2

>>:  Using iframe techniques to obtain visitor QQ implementation ideas and sample code

Recommend

How to design and create adaptive web pages

With the popularization of 3G, more and more peop...

Do you know why vue data is a function?

Official website explanation: When a component is...

How to use HTML form with multiple examples

Nine simple examples analyze the use of HTML form...

Detailed explanation of the difference between docker-compose ports and expose

There are two ways to expose container ports in d...

Docker compose custom network to achieve fixed container IP address

Due to the default bridge network, the IP address...

Steps and pitfalls of upgrading linux mysql5.5 to mysql5.7

Table of contents Linux MySQL 5.5 upgraded to MyS...

How to customize at and cron scheduled tasks in Linux

There are two types of scheduled tasks in Linux s...

JS implementation of carousel carousel case

This article example shares the specific code of ...

js uses cookies to remember user page operations

Preface During the development process, we someti...

Example of implementing translation effect (transfrom: translate) with CSS3

We use the translate parameter to achieve movemen...

A brief discussion on how to write beautiful conditional expressions in JS

Table of contents Multiple conditional statements...

Design a data collector with vue

Table of contents Scenario Core Issues Status mon...

Embedded transplant docker error problem (summary)

After a long period of transplantation and inform...