Docker部署安装Jenkins
一、docker安装Jenkins
1、下载镜像
docker pull jenkins
2、创建文件夹
mkdir -p /opt/jenkens
chown -R 1000 /opt/jenkens
3、启动服务
[root@localhost ~]# docker run -d -p 8888:8080 -p 9999:50000 -v /opt/jenkens:/var/jenkins_home -v /etc/localtime:/etc/localtime -e JAVA_OPTS=-Duser.timezone=Asia/Shanghai --name myjenkins jenkins/jenkins
4、安装激活码
- 用命令查看安装日志,然后找到激活码
[root@localhost ~]# docker logs -f myjenkins
- 查看进程
[root@localhost ~]# ps aux | grep jenkins
5、时区设置
#设置时区
JENKINS_JAVA_OPTIONS="-Duser.timezone=Asia/Shanghai"
#启动docker时设置时区环境变量
docker run --name myjenkins -itd -p 9000:8080 -v /home/xyz/test/jenkins_home:/var/jenkins_home --env JAVA_OPTS="-Duser.timezone=Asia/Shanghai" jenkins/jenkins:latest
二、docker-compose安装
创建一个docker-jenkins-compose.yml文件
version: "3"
services:
jenkins:
image: jenkins/jenkins:lts
ports:
- 9000:8080
- 9999:50000
restart: "always"
container_name: myjenkins
environment:
JAVA_OPTS: -Duser.timezone=Asia/Shanghai
volumes:
- /opt/jenkins/home:/var/jenkins_home
- /var/run/docker.sock:/var/run/docker.sock
- /usr/bin/docker:/usr/bin/docker
privileged: true
user: root
启动Jenkins容器
docker-compose -f docker-jenkins-compose.yml up -d
三、快速启动Jenkins
1、编写启动jenkins的shell脚本
jenkins.sh
#!/bin/bash
docker rm -f myjenkins
docker run --name myjenkins -itd -p 9000:8080 -v /home/xyz/test/jenkins_home:/var/jenkins_home --env JAVA_OPTS="-Xmx8192m" jenkins/jenkins:latest
注意:删除myjenkins后,需要对/home/xyz/test/jenkins_home重新赋权限
sudo chown -R 1000 /home/xyz/test/jenkins_home/
2、启动脚本
bash jenkins.sh