使用 Docker 搭建 Gitlab 和 Jenkins

介绍使用 Docker 搭建 Gitlab 和 Jenkins,安装和配置的步骤。

一、安装

安装gitlab并开启ssh访问
docker run -d \ 
--hostname YOUR_IP \ 
-p 80:80 -p 2222:22 \ 
--name gitlab \ 
--restart always \ 
--volume /opt/data/gitlab/config:/etc/gitlab \ 
--volume /opt/data/gitlab/logs:/var/log/gitlab \ 
--volume /opt/data/gitlab/data:/var/opt/gitlab \ 
-e "GITLAB_OMNIBUS_CONFIG.external_url=http://YOUR_IP" \ 
-e "GITLAB_OMNIBUS_CONFIG.gitlab_rails['gitlab_shell_ssh_port']=2222" \ 
gitlab/gitlab-ce 

以下是查看运行的gitlab的命令,之前安装的有点忘了。

[root@k8s-node1 ~]# docker ps | grep gitlab 
875ba68d2f98   gitlab/gitlab-ce                                    "/assets/wrapper"        4 weeks ago         Up 39 hours (healthy)   0.0.0.0:80->80/tcp, :::80->80/tcp, 443/tcp, 0.0.0.0:2222->22/tcp, :::2222->22/tcp      gitlab 
[root@k8s-node1 ~]# docker inspect   --format "$(curl -s https://gist.githubusercontent.com/efrecon/8ce9c75d518b6eb863f667442d7bc679/raw/run.tpl)" gitlab 
docker run \ 
  --name "/gitlab" \ 
  --runtime "runc" \ 
  --volume "/opt/data/gitlab/logs:/var/log/gitlab" \ 
  --volume "/opt/data/gitlab/data:/var/opt/gitlab" \ 
  --volume "/opt/data/gitlab/config:/etc/gitlab" \ 
  --log-driver "json-file" \ 
  --restart "always" \ 
  --publish "0.0.0.0:2222:22/tcp" \ 
  --publish "0.0.0.0:80:80/tcp" \ 
  --network "bridge" \ 
  --hostname "YOUR_IP" \ 
  --expose "22/tcp" \ 
  --expose "443/tcp" \ 
  --expose "80/tcp" \ 
  --env "GITLAB_OMNIBUS_CONFIG.external_url=http://YOUR_IP" \ 
  --env "GITLAB_OMNIBUS_CONFIG.gitlab_rails['gitlab_shell_ssh_port']=2222" \ 
  --env "PATH=/opt/gitlab/embedded/bin:/opt/gitlab/bin:/assets:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" \ 
  --env "LANG=C.UTF-8" \ 
  --env "EDITOR=/bin/vi" \ 
  --env "TERM=xterm" \ 
  --detach \ 
  "gitlab/gitlab-ce" \ 
  "/assets/wrapper" 
安装jenkins
docker run -d -uroot -p 8080:8080 -p 50000:50000 --name jenkins -v /opt/jenkins/jenkins_home:/var/jenkins_home -v /etc/localtime:/etc/localtime jenkins/jenkins 
[root@k8s-node2 ~]# docker ps | grep jenkins 
08945e1a8733   jenkins/jenkins                                     "/sbin/tini -- /usr/…"   5 weeks ago         Up 15 hours     0.0.0.0:8080->8080/tcp, :::8080->8080/tcp, 0.0.0.0:50000->50000/tcp, :::50000->50000/tcp   jenkins 
[root@k8s-node2 ~]#  docker inspect --format "$(curl -s https://gist.githubusercontent.com/efrecon/8ce9c75d518b6eb863f667442d7bc679/raw/run.tpl)" jenkins 
docker run \ 
  --name "/jenkins" \ 
  --runtime "runc" \ 
  --volume "/opt/jenkins/jenkins_home:/var/jenkins_home" \ 
  --volume "/etc/localtime:/etc/localtime" \ 
  --log-driver "json-file" \ 
  --restart "no" \ 
  --publish "0.0.0.0:50000:50000/tcp" \ 
  --publish "0.0.0.0:8080:8080/tcp" \ 
  --network "bridge" \ 
  --hostname "08945e1a8733" \ 
  --expose "50000/tcp" \ 
  --expose "8080/tcp" \ 
  --env "PATH=/opt/java/openjdk/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" \ 
  --env "LANG=C.UTF-8" \ 
  --env "JENKINS_HOME=/var/jenkins_home" \ 
  --env "JENKINS_SLAVE_AGENT_PORT=50000" \ 
  --env "REF=/usr/share/jenkins/ref" \ 
  --env "JENKINS_VERSION=2.328" \ 
  --env "JENKINS_UC=https://updates.jenkins.io" \ 
  --env "JENKINS_UC_EXPERIMENTAL=https://updates.jenkins.io/experimental" \ 
  --env "JENKINS_INCREMENTALS_REPO_MIRROR=https://repo.jenkins-ci.org/incrementals" \ 
  --env "COPY_REFERENCE_FILE_LOG=/var/jenkins_home/copy_reference_file.log" \ 
  --env "JAVA_HOME=/opt/java/openjdk" \ 
  --label "org.opencontainers.image.description"="The Jenkins Continuous Integration and Delivery server" \ 
  --label "org.opencontainers.image.licenses"="MIT" \ 
  --label "org.opencontainers.image.revision"="65ce4f9169e039738c16fd99faf7a75a6c275496" \ 
  --label "org.opencontainers.image.source"="https://github.com/jenkinsci/docker" \ 
  --label "org.opencontainers.image.title"="Official Jenkins Docker image" \ 
  --label "org.opencontainers.image.url"="https://www.jenkins.io/" \ 
  --label "org.opencontainers.image.vendor"="Jenkins project" \ 
  --label "org.opencontainers.image.version"="2.328" \ 
  --detach \ 
  "jenkins/jenkins" \ 

二、配置

配置密钥

公钥:gitlab的ssh key
私钥:jenkins

●进入jenkins容器

[root@k8s-node2 ~]# docker exec -ti jenkins bash 
root@08945e1a8733:/# cd ~/.ssh/ 
root@08945e1a8733:~/.ssh# ls 
id_rsa  id_rsa.pub  known_hosts 

●复制私钥,添加jenkins凭证
[图片]

●复制公钥,添加gitlab ssh keys
在这里插入图片描述

配置gitlab api token

●gitlab生成 access token

在这里插入图片描述

配置gitlab凭证

前提:安装https://plugins.jenkins.io/gitlab-plugin插件
在这里插入图片描述

配置harbor登录凭证

在这里插入图片描述

配置docker远程

前提:docker开启远程访问,jenkins安装https://plugins.jenkins.io/docker-plugin插件
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值