Operations | Install Jenkins using Docker | Jenkins
Preface
The content of this issue is mainly for learning how to install Jenkins through Docker. It is only for record and reference. I hope it will be helpful to everyone.
Preparation
- System: CentOS 7.9
- Configuration: 4c8g
Quick installation
The following is an example of installing Jenkins using Docker.
Environment setup
- Docker installation documentation: https://docs.docker.com/engine/install/
- Docker Compose installation documentation: https://docs.docker.com/compose/install/
Install Docker
- Make sure the yum package is updated to the latest
yum update
- Uninstall old version
yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine
- Set warehouse source
yum install -y yum-utils
yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo
- start installation
#由于repo中默认只开启stable仓库,故这里安装的是最新稳定版
yum install docker-ce docker-ce-cli containerd.io
- Starting and booting
systemctl start docker
systemctl enable docker
- Verify installation was successful
docker version
Install Docker Compose
The following is the independent installation method of Docker Compose. For other methods, please refer to the official documentation.
- Installing Compose standalone
curl -SL https://github.com/docker/compose/releases/download/v2.12.2/docker-compose-linux-x86_64 -o /usr/local/bin/docker-compose
- Command execution failed
sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
- Set file or folder permissions
chmod +x /usr/local/bin/docker-compose
- Verify whether the installation is successful
docker-compose version
Install Jenkins
Jenkins Chinese official website: https://www.jenkins.io/zh/
Deploy using Docker Compose
- Create a folder anywhere in the system. This document uses
~/opt/docker/jenkins
as an example
mkdir -p ~/opt/docker/jenkins && cd ~/opt/docker/jenkins
Create some necessary files or folders, keeping the directory structure as shown in the example:
mkdir -p ./{config,data,logs}
.
├── docker
│ └── jenkins
│ ├── docker-compose.yml
│ ├── data
│ └── config
│ └── logs
This is for reference only, you can follow your own preferences.
Note: In subsequent operations, all data generated by Jenkins will be saved in this directory, please save it properly.
- create
docker-compose.yaml
version: '3'
services: # 集合
docker_jenkins:
user: root # 为了避免一些权限问题 在这我使用了root
privileged: true
restart: always # 重启方式
image: jenkins/jenkins:lts # 指定服务所使用的镜像 在这里我选择了 LTS (长期支持)
container_name: jenkins # 容器名称
ports: # 对外暴露的端口定义
- 8082:8080 # 访问Jenkins服务端口
- 50000:50000
environment:
TZ: Asia/Shanghai
volumes: # 卷挂载路径
- ./data:/var/jenkins_home
- /var/run/docker.sock:/var/run/docker.sock
- /usr/bin/docker:/usr/bin/docker # 这是为了我们可以在容器内使用docker命令
- /usr/local/bin/docker-compose:/usr/local/bin/docker-compose
/usr/share/jenkins
Contains some Jenkins configurations, such as plug-ins, which can be mapped to the host if necessary.
- Start service
docker-compose up -d
View logs in real time:
docker-compose logs -f
- address
Access address after installation is complete:http://{部署Jenkins所在服务IP}:8080
There will be a few minutes of waiting time here
Deploy using Docker
- Create a folder anywhere in the system. This document uses
~/opt/docker/jenkins
as an example
mkdir -p ~/opt/docker/jenkins && cd ~/opt/docker/jenkins
Create some necessary files or folders, keeping the directory structure as shown in the example:
.
├── docker
│ └── jenkins
│ ├── data
│ └── config
│ └── logs
- Start service
docker run \
-u root \
--rm \
-d \
-p 8080:8080 \
-p 50000:50000 \
-v /opt/docker/jenkins/data:/var/jenkins_home \
-v /var/run/docker.sock:/var/run/docker.sock \
--name jenkins \
jenkins/jenkins:lts
Check the running log:
docker ps // 查看containerId
docker logs [ID | NAME]
View real-time logs:
docker logs -f [ID | NAME]
Pay attention to check whether 8080 is already occupied! If the modified port is occupied
- address
Access address after installation is complete:http://{部署Jenkins所在服务IP}:8080
There will be a few minutes of waiting time here
user's guidance
initialization
For details, see the official website tutorial:https://www.jenkins.io
Unlock Jenkins
- method one
Enter the Jenkins container:docker exec -it {Jenkins容器名} bash
For example:docker exec -it jenkins bash
View password:cat /var/jenkins_home/secrets/initialAdminPassword
Copy the password into the input box
- Method 2
Check the log to get the password
docker logs -f [ID|NAME]
或
docker-compose logs -f
After entering the password correctly, follow the recommended instructions to boot the operation, and wait until the boot installation is completed to enter the Jenkins home page.
Default plugin
If there are no special requirements, just choose the recommended plug-in to install.
Create admin user
Important configuration
Configure address and email
Plug-in management
Install git parameters
- Search plugin
-
Entry
首页
–系统管理
–插件管理
–可选插件
Interface -
Search
git paremeters
plug-in and click to install
- Configure plugin
- Check
This project is parameterized
in the project general items and selectGit Parameter
Install nodejs
- Search plugin
-
Entry
首页
–系统管理
–插件管理
–可选插件
Interface -
Search
nodejs
plug-in and click to install
- Configure plugin
- Entry
首页
–系统管理
–全局工具配置
Interface - Found
NodeJS
Configuration Bar
Install Publish Over SSH
- Search plugin
-
Entry
首页
–系统管理
–插件管理
–可选插件
Interface -
Search
ssh
plug-in and click to install
- Configure plugin
- Entry
首页
–系统管理
–全局工具配置
Interface - Found
SSH Servers
Configuration Bar
Install Maven
- Search plugin
-
Entry
首页
–系统管理
–插件管理
–可选插件
Interface -
Search
Maven Integration
plug-in and click to install
- Configure plugin
- Entry
首页
–系统管理
–全局工具配置
Interface - Found
maven–maven
Configuration Bar
Install Chinese language
- Search plugin
-
Entry
首页
–系统管理
–插件管理
–可选插件
Interface -
Search
Locale
plug-in and click to install
After the installation is complete, enter /restart
after the path in the address bar to restart Jenkins
- Configure plugin
- Entry
首页
–系统管理
–系统配置
Interface - Find the
Default language
configuration bar and enterzh_CN
orzh_TW
If the above method does not work, you can try to search for Localization: Chinese (Simplified)
plug-in
The latest version of Jenkins may have incomplete or ineffective translations
FAQ
The installation is complete but the Jenkins instance is offline.
The reason is that Jenkins will check the network connection before downloading the plug-in, and it will read the URL in the default.json
file, which is located under /var/jenkins_home/updates
. connectionCheckUrl
The default is to access the Google address. If you do not circumvent the wall, an error may occur, so change the value of connectionCheckUrl
to www.baidu.com
. , restart the service after making changes.
When the installation is completed, the access address appears HTTP ERROR 503
If this screen appears, it is most likely a firewall problem, such as: the currently accessed port is not open, etc.
Jenkins initialization plug-in installation exception, unable to proceed to the next step
- method one
You can try changing the network or checking whether a proxy is enabled or something like that.
- Method 2
This method is to install Jenkins on the host machine. As for Docker, please refer to the processing flow of this method.
- Stop the Jenkins service
sudo systemctl stop jenkins
- Revision
config.xml
Text item
sudo vim /var/lib/jenkins/config.xml
Modify line 10 <useSecurity>true</useSecurity> to: <useSecurity>false</useSecurity>
Delete lines <authorizationStrategy …/> and <securityRealm …> to</securityRealm>
end
That’s it for this issue. Friends passing by, please remember to support us!