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

How to install Mysql5.7 in Centos6

environment Centos 6.6 MySQL 5.7 Install If the s...

How to choose transaction isolation level in MySQL project

introduction Let's start with our content. I ...

MySQL database terminal - common operation command codes

Table of contents 1. Add users 2. Change the user...

Native JS to achieve book flipping effects

This article shares with you a book flipping effe...

Summary of Docker Data Storage

Before reading this article, I hope you have a ba...

How to implement Vue binding class and binding inline style

Table of contents Binding Class Binding inline st...

Implementation of breakpoint resume in Node.js

Preface Normal business needs: upload pictures, E...

MySQL date and time addition and subtraction sample code

Table of contents 1.MySQL adds or subtracts a tim...

Detailed explanation of Docker Secret management and use

1. What is Docker Secret 1. Scenario display We k...

Use Navicate to connect to MySQL on Alibaba Cloud Server

1. First enter the server's mysql to modify p...

Use the Linux seq command to generate a sequence of numbers (recommended)

The Linux seq command can generate lists of numbe...

JavaScript Reflection Learning Tips

Table of contents 1. Introduction 2. Interface 3....

Solutions to common problems using Elasticsearch

1. Using it with redis will cause Netty startup c...