-
更新系统:
sudo apt update sudo apt upgrade
-
安装必要的依赖:
sudo apt install apt-transport-https ca-certificates curl software-properties-common
-
添加Docker官方的GPG密钥:
curl -fsSL https://download.docker.com/linux/debian/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
-
添加Docker的APT源:
echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/debian bullseye stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
-
更新APT软件包索引:
sudo apt update
-
安装Docker引擎:
sudo apt install docker-ce docker-ce-cli containerd.io
-
验证Docker是否成功安装:
sudo docker run hello-world
如果一切顺利,将会输出"Hello from Docker!"的信息。
如果出现apt update 失败需将apt源换成阿里源
文件在 /etc/apt/下
- 备份原来的文件
cp /etc/apt/source.list /etc/apt/source.list_bk
2.将以下内容进行替换
deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
运行以下 docker 命令安装Jenkins
sudo docker run \
-u root \
-it \
-d \
--name jenkins \
-p 9000:8080 \
-v /opt/docker/jenkins_home:/var/jenkins_home \
-v /var/run/docker.sock:/var/run/docker.sock \
jenkins/jenkins
将jenkins文件挂载在宿主机/opt/docker/jenkins_home目录下,将hudson.model.UpdateCenter.xml中的url换成 https://mirrors.tuna.tsinghua.edu.cn/jenkins/updates/update-center.json,并重启jenkins
cd /opt/docker/jenkins_home
sudo vim hudson.model.UpdateCenter.xml
替换 https://mirrors.tuna.tsinghua.edu.cn/jenkins/updates/update-center.json
sudo docker restart jenkins
sudo docker exec -it jenkins bash
jenkins 容器中需要安装docker,按照以上安装docker 的命令安装,设置docker的daemon
vim /etc/docker/daemon.json
粘贴以下内容
{
"registry-mirrors": [
"https://registry.docker-cn.com"
],
"insecure-registries": [
"你的dockerhub-Ip:5000"
]
}
重启jenkins容器内的docker
service docker restart
浏览器输入xxxxxx:9000进入jenkins页面,初始密码路径在页面可以看到
进入按照新手推荐安装插件,然后设置用户名密码。
然后jenkins 左侧找到系统管理,这里可以的插件管理可以安装插件,全局工具配置可以设置jdk,mvn等等,系统设置可以设置需要发布的服务器。