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

Vue local component data sharing Vue.observable() usage

As components become more detailed, you will enco...

Let's talk about the LIMIT statement in MySQL in detail

Table of contents question Server layer and stora...

Detailed explanation of the cache implementation principle of Vue computed

Table of contents Initialize computed Dependency ...

Some basic instructions of docker

Table of contents Some basic instructions 1. Chec...

...

js to achieve a simple magnifying glass effect

This article shares the specific code of js to ac...

Nginx sample code for implementing dynamic and static separation

In combination with the scenario in this article,...

How to create, save, and load Docker images

There are three ways to create an image: creating...

Detailed explanation of Vue's monitoring properties

Table of contents Vue monitor properties What is ...

How to install ionCube extension using pagoda

1. First install the pagoda Installation requirem...

HTML+CSS implementation code for rounded rectangle

I was bored and suddenly thought of the implementa...

Let me teach you how to use font icons in CSS

First of all, what is a font icon? On the surface...