1. Preparation
Create the folder /opt/docker-home/jenkins/jenkins_home and configure the folder permissions.
$ cd `/opt/docker-home/jenkins
$ sudo chown -R 1000 jenkins_home
2. docker-compose.yml
Create the file docker-compose.yml under the /opt/docker-home/jenkins file with the following configuration.
version: "3"
services:
app:
image: jenkins/jenkins:2.282-alpine
container_name: jenkins
restart: always
environment:
TZ: Asia/Shanghai
volumes:
- ./jenkins_home:/var/jenkins_home
ports:
- "8080:8080"
- "50000:50000"
3. Start
$ docker-compose up -d
Check the file /opt/docker-home/jenkins/jenkins_home/secrets/initialAdminPassword after starting, this is the password after initialization, which is needed for jenkins initialization.
4. Plugin Center Modification
After initialization, you can modify the plug-in center as a domestic mirror source to download faster. Go to Configure System Configuration -> Plugin Management -> Advanced -> Upgrade Site in order, modify it to https://jenkins-zh.cn/tutorial/management/plugin/update-center/ and submit to save.
5. Installing ansible in a container
$ docker exec -it --user root jenkins bash
After entering the container, modify the image source and change the contents of /etc/apk/repositories to the following.
# http://dl-cdn.alpinelinux.org/alpine/v3.12/main
# http://dl-cdn.alpinelinux.org/alpine/v3.12/community
https://mirrors.cloud.tencent.com/alpine/v3.12/main
https://mirrors.cloud.tencent.com/alpine/v3.12/community
Installation.
$ apk add ansible