1、先下载Jenkins的镜像

[root@localhost ~]# docker pull jenkinsci/blueocean
Using default tag: latest
Trying to pull repository docker.io/jenkinsci/blueocean ... 
latest: Pulling from docker.io/jenkinsci/blueocean
5843afab3874: Pull complete 
b0ff89958cbf: Pull complete 
3cdb1bf818c0: Pull complete 
24f6e8759396: Pull complete 
71e497d785d0: Pull complete 
d971e78d2fd6: Pull complete 
a9e65fb03680: Pull complete 
3d33c9c11b3b: Pull complete 
4ceab90478aa: Pull complete 
378420fcd1d1: Pull complete 
5946eacdd636: Pull complete 
89e21d655446: Pull complete 
c08e7132fb41: Pull complete 
623399f38d68: Pull complete 
c3dd59e2382f: Pull complete 
75002d6299a9: Pull complete 
1f7838b5d573: Pull complete 
0c985732b926: Pull complete 
Digest: sha256:61ad88a3883ed341762e9ae9af041ea4c38c5aed10da82bf93bc0b21f58f53fc
Status: Downloaded newer image for docker.io/jenkinsci/blueocean:latest

2、查看镜像

[root@localhost ~]# docker images
REPOSITORY                      TAG                 IMAGE ID            CREATED             SIZE
docker.io/jenkinsci/blueocean   latest              745bd9d479f2        6 hours ago         716MB

3、将镜像启动成容器

docker run  \
--name=jenkins \
--privileged=true \
--restart=always \
--network=host \
-p 8080:8080  \
-p 5000:5000  \
-v /opt/jenkins:/var/jenkins_home  \
jenkinsci/blueocean
  • –-name:容器名,此处命名为mysql
  • --privileged=true 使用该参数,container内的root拥有真正的root权限
  • --restart=always 自动重启容器
  • --network=host 启动容器的时候使用 host 模式

执行以上命令时会提示


touch: cannot touch '/var/jenkins_home/copy_reference_file.log': Permission denied
Can not write to /var/jenkins_home/copy_reference_file.log. Wrong volume permissions?

需要修改下目录权限, 因为当映射本地数据卷时,/opt/jenkins目录的拥有者为root用户,而容器中jenkins user的uid为1000
执行如下命令即可:

chown -R 1000:1000 /opt/jenkins

然后先停止并删除刚才启动的容器,重新执行启动命令:

docker run  \
--name=jenkins \
--privileged=true \
--restart=always \
--network=host \
-p 8080:8080  \
-p 5000:5000  \
-v /opt/jenkins:/var/jenkins_home  \
jenkinsci/blueocean

PS:第一次启动的时候正在加载jenkins大概会等待3-10分钟。

4、配置Jenkins

当终端出现以下内容时,就说明已经启动成功了
WX20210804-005650@2x.png

访问http://ip:8080,将上面的passwd复制粘贴进去就可以了

当所有的插件都下载安装完成之后,终端上ctrl+c停止容器,使其后台运行

[root@localhost ~]# docker start jenkins
jenkins
最后修改:2021 年 08 月 04 日 03 : 58 PM
如果觉得我的文章对你有用,请随意赞赏