Docker 搭建Jenkins

  |  
阅读次数
  |  
字数 304
  |  
时长 ≈ 2 分钟

使用Docker搭建Jenkins服务,因为Jenkins Job需要执行Python脚本,需要安装Paramiko模块,所以需要编写下Dockerfile进行构建。

目录结构

jenkins

  • jenkins_home
  • dockerfile_2.257
    • build.sh
    • Dockerfile
  • docker-compose.yml

编写dockerfile_2.257/Dockerfile:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
FROM jenkins/jenkins:2.257

USER root

RUN sed -i 's/deb.debian.org/mirrors.aliyun.com/g' /etc/apt/sources.list \
&& sed -i 's/security.debian.org/mirrors.aliyun.com/g' /etc/apt/sources.list \
&& apt-get clean \
&& apt-get update \
&& apt-get install -y python-pip \
&& rm -rf /var/lib/apt/lists/* \
&& pip install -i https://pypi.tuna.tsinghua.edu.cn/simple cffi \
&& pip install -i https://pypi.tuna.tsinghua.edu.cn/simple paramiko

USER jenkins

编写dockerfile_2.257/build.sh:

1
docker build -t tisson/jenkins:2.257 .

编写docker-compose.yml:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
version: "3.8"

services:
jenkins:
container_name: ts_jenkins
image: tisson/jenkins:2.257
environment:
TZ: "Asia/Shanghai"
JAVA_OPTS: "-Djava.awt.headless=true"
ports:
- "8080:8080"
volumes:
- "./jenkins_home:/var/jenkins_home"
- "/var/run/docker.sock:/var/run/docker.sock"
- "/etc/localtime:/etc/localtime"
restart: always

新建Jenkins家目录,以便映射

在同级目录新建jenkins_home文件夹

启动

创建容器并后台启动:

1
docker-compose up -d

查看日志

查看运行日志:

1
docker-compose logs -f

校验

在浏览器输入http://localhost:8080进行校验,输入日志显示的秘钥初始化Jenkins