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

mysql8 Common Table Expression CTE usage example analysis

This article uses an example to describe how to u...

How to use Vue-router routing

Table of contents 1. Description 2. Installation ...

How to solve the Mysql transaction operation failure

How to solve the Mysql transaction operation fail...

js dynamically generates tables (node ​​operations)

This article example shares the specific code of ...

Architecture and component description of docker private library Harbor

This article will explain the composition of the ...

MySQL database advanced query and multi-table query

MySQL multi-table query Add a worksheet -- User t...

A brief analysis of CSS :is() and :where() coming to browsers soon

Preview versions of Safari (Technology Preview 10...

Vue.js implements the code of clicking the icon to zoom in and leaving

The previous article introduced how Vue can reali...

Linux directory switching implementation code example

Switching files is a common operation in Linux. W...

A detailed discussion of evaluation strategies in JavaScript

Table of contents A chestnut to cover it Paramete...

web.config (IIS) and .htaccess (Apache) configuration

xml <?xml version="1.0" encoding=&qu...

vue front-end HbuliderEslint real-time verification automatic repair settings

Table of contents ESLint plugin installation in H...

innodb_flush_method value method (example explanation)

Several typical values ​​of innodb_flush_method f...