安装docker-ce
如果你之前安装过 docker,请先删掉:
yum remove docker docker-common docker-selinux docker-engine
下载repo文件:
wget -O /etc/yum.repos.d/docker-ce.repo https://download.docker.com/linux/centos/docker-ce.repo
把软件仓库地址替换为 TUNA:
sed -i 's+download.docker.com+mirrors.tuna.tsinghua.edu.cn/docker-ce+' /etc/yum.repos.d/docker-ce.repo
最后安装:
yum makecache fast
yum install docker-ce
查看docker版本:
docker version
安装docker-compose
下载docker-compose执行文件:
curl -L https://github.com/docker/compose/releases/download/1.17.1/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
验证安装结果:
docker-compose -v
docker-compose version 1.17.1, build 6d101fb
下载镜像文件
下载gitlab-ce:
docker pull gitlab/gitlab-ce:latest
下载sonarqube:
docker pull sonarqube:latest
下载jenkins:
docker pull jenkins:latest
查看下载的镜像:
docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
gitlab/gitlab-ce latest 960751451a26 5 days ago 1.38GB
sonarqube latest c1637bd4502f 2 weeks ago 934MB
jenkins latest 3f08dc4f3f5d 3 weeks ago 809MB
启动容器
编写docker-compose.yml文件:
version: '2'
services:
gitlab:
image: gitlab/gitlab-ce:latest
ports:
- "443:443"
- "80:80"
- "2222:22"
networks:
- devops
volumes:
- /data/gitlab/config:/etc/gitlab
- /data/gitlab/logs:/var/log/gitlab
- /data/gitlab/data:/var/opt/gitlab
jenkins:
image: jenkins:latest
ports:
- "8080:8080"
- "50000:50000"
networks:
- devops
volumes:
- /data/jenkins:/var/jenkins_home
- /var/run/docker.sock:/var/run/docker.sock
sonarqube:
image: sonarqube:latest
ports:
- "9000:9000"
- "9092:9092"
networks:
- devops
networks:
devops:
driver: bridge
创建gitlab容器挂载的目录结构,如果不是root权限启动,需要修改权限为777:
mkdir /data/gitlab/{config,logs,data} -p
创建jenkins容器挂载的目录:
mkdir /data/jenkins
chmod 777 /data/jenkins
在docker-compose.yml相同目录下,启动gitlab:
docker-compose up -d gitlab
gitlab容器的启动时间较长,大概需要5分钟容器才能处于正常状态:
docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
8b7d4085ee8b gitlab/gitlab-ce:latest "/assets/wrapper" 22 minutes ago Up 22 minutes (healthy) 0.0.0.0:80->80/tcp, 0.0.0.0:443->443/tcp, 0.0.0.0:2222->22/tcp devops_gitlab_1
启动后,登录web界面,设置密码,默认用户名为root.
启动jenkins:
docker-compose up -d jenkins
查看启动状态:
docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d919b9c60882 jenkins:latest "/bin/tini -- /usr..." 5 minutes ago Up 5 minutes 0.0.0.0:8080->8080/tcp, 0.0.0.0:50000->50000/tcp devops_jenkins_1
查看密码文件:
docker logs devops_jenkins_1
...
*************************************************************
*************************************************************
*************************************************************
Jenkins initial setup is required. An admin user has been created and a password generated.
Please use the following password to proceed to installation:
febb3f47881543c697764c9ee9eba888
This may also be found at: /var/jenkins_home/secrets/initialAdminPassword
*************************************************************
*************************************************************
*************************************************************
...
用此token就可登录web界面。
启动sonarqube:
docker-compose up -d sonarqube
查看启动状态:
docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
13f85ff7af39 sonarqube:latest "./bin/run.sh" 12 seconds ago Up 7 seconds 0.0.0.0:9000->9000/tcp, 0.0.0.0:9092->9092/tcp devops_sonarqube_1
使用ip:9000方式登录web界面,默认的登录密码为admin/admin。