1. 下载镜像

## 搜索并下载jenkins镜像
docker search jenkins
docker pull jenkins/jenkins:lts

2. 创建容器

# 创建目录存放Jenkins数据
mkdir -p /data/jenkins_home
# 设置目录权限
chown 1000:1000 /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时区
进入菜单【系统管理】 -> 【脚本命令行】
image.png
执行以下命令
System.setProperty('org.apache.commons.jelly.tags.fmt.timeZone', 'Asia/Shanghai')

安装Over SSH插件

插件首页: https://plugins.jenkins.io/publish-over-ssh/

  1. Using the GUI: From your Jenkins dashboard navigate to Manage Jenkins > Manage Plugins and select the Available tab. Locate this plugin by searching for publish-over-ssh.
  2. Using the CLI tool:
    jenkins-plugin-cli --plugins publish-over-ssh:1.25
  3. Using direct upload. Download one of the releases and upload it to your Jenkins instance.

YYGP
25 声望11 粉丝

写BUG