Detailed tutorial on installing the jenkins container in a docker environment

Detailed tutorial on installing the jenkins container in a docker environment

Recommended Docker learning materials: https://www.runoob.com/docker/docker-tutorial.html

1. Centos7 environment docker installation

First go to the official website to download the image, docker image official: https://hub.docker.com/

1. Install the latest version

yum install -y yum-utils 
device-mapper-persistent-data lvm2

2. Add docker source

yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

3. Install Docker

yum install docker-ce

Note: Check whether Docker is installed?

yum list installed | grep docker

If you want to uninstall, you can enter the command:

 yum remove xxx xxxx xxx

4. Set DNS, accelerator, and bind IP in /etc/docker/daemon.json . Generally, there is no daemon.json file, so you need to create it yourself.

{
 "dns" : [
 "114.114.114.114",
 "8.8.8.8"
 ],
 #Accelerator, which can increase the speed of downloading images. You can also configure it to the Alibaba Cloud mirror address "registry-mirrors": ["https://registry-docker.com"],
 "bip":"172.17.5.1/24" 
}

5. After installation, check the docker version and information

docker version
docker info

6. Set Docker to start when the virtual machine starts

sudo chkconfig docker on

7. Start Docker

sudo service docker start

2. Install Jenkins with docker

1. Generally, for the convenience of management, customize the IP segment of the container. Here I customize my network name: mynetwork

docker network create --subnet=172.18.0.0/16 mynetwork

The definition is complete and can be viewed: docker network ls

2. Download the jinkins image:
Format: docker pull image description: version number. If the version number is not specified, the latest version number is downloaded by default: latest

docker pull jenkins/jenkins:latest

3. Authorize the container account In order to prevent Jenkins from reinstalling when migrating or recreating the container, you need to mount the data in the corresponding directory during the first installation. In my case, I mount the data to this directory: /home/docker/data/jenkins . Since the container account corresponds to 1000 on the host machine, you need to authorize the mount directory /home/docker/data/jenkins , otherwise the creation will fail when the container is started:

 chown -R 1000 /home/docker/data/jenkins

4. Create a container and start it when Linux starts, and specify a fixed IP

docker run --net mynetwork --ip 172.18.0.4 
-v /home/docker/data/project/jenkins:/home/docker/data/jenkins 
-v /home/docker/var/jenkins/jenkins_home:/var/jenkins_home 
-v /etc/localtime:/etc/localtime
-e JAVA_OPTS=-Duser.timezone=Asia/Shanghai 
-dit --name my-jenkins 
-p 8080:8080 -p 50000:50000 
--restart=always jenkins/jenkins:latest

explain:
1. -v /home/docker/data/project/jenkins:/home/docker/data/jenkins
This directory is mounted to facilitate writing and executing scripts on the host machine, and the Jenkins container can also call it;

2. -v /home/docker/var/jenkins/jenkins_home:/var/jenkins_home
This directory is mounted to facilitate Jenkins migration without reinstalling

Note: The port number -p 50000:50000 should be the default and should not be modified. Only the port number -p 8080:8080 can be set according to our needs.

6. Installation is successful, check:

docker ps -a | grep jenkins 

insert image description here

5. Enter the container:
As root user:

docker exec -it -u root my-jenkins /bin/bash

Default user: docker exec -it my-jenkins /bin/bash

6. Install the vim command in the container for the first time:

apt-get update

apt-get install vim

7. There are two ways to exit the container:
1) exit
2) Ctrl + P + Q

Summarize

This is the end of this article about installing jenkins container in docker environment. For more information about installing jenkins container in docker environment, please search 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:
  • Using Docker+jenkins+python3 environment to build a super detailed tutorial
  • Detailed tutorial on building a continuous integration delivery environment based on Docker+K8S+GitLab/SVN+Jenkins+Harbor
  • When setting up Jenkins in Docker environment, the console log shows garbled Chinese characters when building tasks
  • About the problem of starting the Jenkins environment with Docker

<<:  Native JS to implement real-time clock

>>:  How to quickly repair corrupted MySQL database files using the myisamchk and mysqlcheck tools

Recommend

MySQL5.7 parallel replication principle and implementation

Anyone who has a little knowledge of data operati...

JS realizes the scrolling effect of announcement online

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

Detailed explanation of InnoDB storage files in MySQL

Physically speaking, an InnoDB table consists of ...

mysql: [ERROR] unknown option '--skip-grant-tables'

MySQL database reports ERROR 1045 (28000): Access...

Nginx cache files and dynamic files automatic balancing configuration script

nginx Nginx (engine x) is a high-performance HTTP...

JavaScript Timer Details

Table of contents 1. Brief Introduction 2. setInt...

Detailed tutorial on compiling and installing python3.6 on linux

1. First go to the official website https://www.p...

Some front-end basics (html, css) encountered in practice

1. The div css mouse hand shape is cursor:pointer;...

Javascript destructuring assignment details

Table of contents 1. Array deconstruction 2. Obje...

Apache Log4j2 reports a nuclear-level vulnerability and a quick fix

Apache Log4j2 reported a nuclear-level vulnerabil...

How to configure static network connection in Linux

Configuring network connectivity for Linux system...

Mysql 8.0.18 hash join test (recommended)

Hash Join Hash Join does not require any indexes ...