Docker安装Jenkins

## 搜索并下载jenkins镜像
docker search jenkins
docker pull jenkins/jenkins:lts
# 创建容器
mkdir -p /data/jenkins_home
chmod 777 /data/jenkins_home
docker run -d -p 10240:8080 -p 10241:50000 -v /data/jenkins_home:/var/jenkins_home -v /etc/localtime:/etc/localtime -v /usr/local/apache-maven-3.8.6:/usr/local/apache-maven-3.8.6 -v /usr/local/apache-ant-1.10.12:/usr/local/apache-ant-1.10.12 -v /usr/local/jdk1.8.0_341:/usr/local/jdk1.8.0_341 -v /usr/local/node-v16.17.1-linux-x64:/usr/local/node-v16.17.1-linux-x64 --restart=always  --add-host host.docker.internal:host-gateway --name jenkins jenkins/jenkins:lts
# -p 10240:8080 映射8080端口到宿主机的10240上
# -p 10241:50000 映射50000端口到宿主机的10241上

# -v /data/jenkins_home:/var/jenkins_home 将容器jenkins工作目录映射到宿主机的/data/jenkins_home目录

# -v /etc/localtime:/etc/localtime 让容器使用和服务器同样的时间设置

# --restart=always 容器开机自启

#  --add-host host.docker.internal:host-gateway 容器内可用host.docker.internal域名访问宿主机

## 以下可以按需选择
# -v /usr/local/apache-maven-3.8.5:/usr/local/apache-maven-3.8.5 映射Maven
# -v /usr/local/apache-ant-1.9.16:/usr/local/apache-ant-1.9.16 映射Ant
# -v /usr/local/jdk1.8.0_301:/usr/local/jdk1.8.0_301 映射JDK
# -v /usr/local/node-v16.15.0-linux-x64:/usr/local/node-v16.15.0-linux-x64 映射NodeJs。

Maven仓库地址在宿主机是/data/jenkins_home/.m2, 虚拟机是/var/jenkins_home/.m2


进入Jenkins容器: docker exec -it jenkins /bin/bash


root帐号进入
使用: docker exec -it --user root jenkins /bin/bash, root帐号登录后可以安装软件, 如安装vim:

apt-get update
apt-get install vim -y

修改Jenkins时区
进入菜单【系统管理】 -> 【脚本命令行】

执行以下命令
System.setProperty('org.apache.commons.jelly.tags.fmt.timeZone', 'Asia/Shanghai')

你可能感兴趣的:(jenkinsdocker)