docker安装gitlab服务器

一、安装Docker

1.安装docker依赖包

[root@gitlab ~]# yum -y install yum-utils device-mapper-persistent-data lvm2

2.添加Docker-ce镜像源并安装
1.1)国外源(适合在国外工作的朋友)

[root@gitlab ~]# yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo

1.2)国内阿里云源(适合在国内工作的朋友)

[root@gitlab ~]# yum-config-manager \
--add-repo \
http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

2)服务器的包信息下载到本地电脑缓存起来

[root@gitlab ~]# yum makecache fast

3)安装docker CE

[root@gitlab ~]# yum -y install docker-ce

4)配置下载docker镜像加速器

国外加速器:

[root@gitlab ~]# curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://bc437cce.m.daocloud.io

国内阿里云加速器:

vim /etc/docker/daemon.json

#输入下面内容并保存:

{
"registry-mirrors": [https://9w1hl6qt.mirror.aliyuncs.com]
}

5)重载systemctl并自动和开启自启动docker

[root@gitlab ~]# systemctl daemon-reload
[root@gitlab ~]# systemctl start docker
[root@gitlab ~]# systemctl enable docker
[root@gitlab ~]# docker --version 
Docker version 18.09.0, build 4d60db4

二、安装Docker-compose

下载Docker-compose二进制文件并添加执行权限

[root@gitlab ~]# curl -L https://github.com/docker/compose/releases/download/1.23.2/docker-compose-`uname -s-uname -m` -o /usr/local/bin/docker-compose
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 617 0 617 0 0 590 0 --:--:-- 0:00:01 --:--:-- 590
100 11.2M 100 11.2M 0 0 498k 0 0:00:23 0:00:23 --:--:-- 737k
[root@gitlab ~]# chmod +x /usr/local/bin/docker-compose
[root@gitlab ~]# docker-compose --version
docker-compose version 1.23.2, build 1110ad01

三、安装Gitlab

1)编辑docker-compose的yml文件

[root@gitlab ~]# mkdir gitlab
[root@gitlab ~]# cd gitlab
[root@gitlab gitlab]# vim docker-compose.yml
version: '2'
services:
  gitlab:
   image: 'twang2218/gitlab-ce-zh:latest'
   container_name: "gitlab"
   restart: unless-stopped
   privileged: true
   hostname: 'gitlab'
   environment:
   TZ: 'Asia/Shanghai'
   GITLAB_OMNIBUS_CONFIG: |
    external_url 'http://ip或者用nginx做反代的域名'
    gitlab_rails['time_zone'] = 'Asia/Shanghai'
    gitlab_rails['smtp_enable'] = true
    gitlab_rails['smtp_address'] = "smtp.163.com"
    gitlab_rails['smtp_port'] = 465
    gitlab_rails['smtp_user_name'] = "xxxxxx@163.com"
    gitlab_rails['smtp_password'] = "授权码"
    gitlab_rails['smtp_domain'] = "163.com"
    gitlab_rails['smtp_authentication'] = "login"
    gitlab_rails['smtp_enable_starttls_auto'] = true
    gitlab_rails['smtp_tls'] = true
    gitlab_rails['gitlab_email_from'] = 'xxxxxx@163.com'
    gitlab_rails['gitlab_shell_ssh_port'] = 22
   ports:
    - '8181:80'
    - '8443:443'
    - '22:22'
   volumes:
    - /opt/gitlab/config:/etc/gitlab
    - /opt/gitlab/data:/var/opt/gitlab
    - /opt/gitlab/logs:/var/log/gitlab

端口映射说明以及注意事项:

gitlab镜像官方推荐容器80端口映射宿主机8181端口
gitlab镜像官方推荐容器443端口映射宿主机8443端口
gitlab镜像官方推荐容器22端口映射宿主机22端口

⭐️头两行不能顶头写,要分别都空一行,可以去yml文件检测网站进行检测:
www.bejson.com/validators/yaml_edi...

2)创建相关目录

[root@gitlab gitlab]# mkdir -p /opt/gitlab/{config,data,logs}
[root@gitlab gitlab]# ls -l /opt/gitlab/
total 0
drwxr-xr-x 2 root root 6 Dec 22 12:03 config
drwxr-xr-x 2 root root 6 Dec 22 12:03 data
drwxr-xr-x 2 root root 6 Dec 22 12:03 logs

目录说明如下:

config 存储 GitLab 配置信息
data 存储数据库
logs 存储日志

3)拉取gitlab中文版镜像

[root@gitlab gitlab]# docker pull twang2218/gitlab-ce-zh:latest
latest: Pulling from twang2218/gitlab-ce-zh
8ee29e426c26: Pull complete
6e83b260b73b: Pull complete
e26b65fd1143: Pull complete
40dca07f8222: Pull complete
b420ae9e10b3: Pull complete
a218309dd589: Pull complete
5c60fd7ba0ce: Pull complete
659c2144b5a3: Pull complete
8289bbac0d0e: Pull complete
31bbd150e8a7: Pull complete
9114e78243fa: Pull complete
e242e5cd1314: Pull complete
0a079dc3f92c: Pull complete
f0e195b09fd2: Pull complete
6e23346e2f58: Pull complete
91f00659be69: Pull complete
a1031bcc5b2c: Pull complete
e3074327c7b1: Pull complete
a917618dbe42: Pull complete
Digest: sha256:62686b74c6fca5ece8ed582d03a126c5988423dd8a19ce70e9a22357ffcaf1c8
Status: Downloaded newer image for twang2218/gitlab-ce-zh:latest

[root@gitlab gitlab]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
twang2218/gitlab-ce-zh latest 18da462b5ff5 4 months ago 1.61GB

4)启动gitlab的容器
在启动前,先要修改宿主机的22端口,因为宿主机占用了22端口,所以启动容器会失败,因为映射不过来,修改如下:

vim /etc/ssh/sshd_config

默认在第17行修改:Port 2222
修改后,重启sshd:systemctl restart sshd

[root@gitlab gitlab]# netstat -tulnp | grep 22
tcp 0 0 0.0.0.0:2222 0.0.0.0: LISTEN 31889/sshd
tcp6 0 0 :::2222 ::: LISTEN 31889/sshd

正式启动:

[root@gitlab gitlab]# docker-compose up -d
Creating network "gitlab_default" with the default driver
Creating gitlab ... done

[root@gitlab gitlab]# docker-compose ps
Name Command State Ports
gitlab /assets/wrapper Up (healthy) 0.0.0.0:22->22/tcp, 0.0.0.0:8443->443/tcp, 0.0.0.0:8181->80/tcp

[root@gitlab gitlab]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
814e559dc728 twang2218/gitlab-ce-zh:latest "/assets/wrapper" 5 minutes ago Up 5 minutes (healthy) 0.0.0.0:22->22/tcp, 0.0.0.0:8181->80/tcp, 0.0.0.0:8443->443/tcp gitlab

5)gitlab设置开机启动

[root@gitlab gitlab]# chmod +x /etc/rc.local
[root@gitlab gitlab]# ls -l /etc/rc.local
lrwxrwxrwx 1 root root 13 Dec 3 14:31 /etc/rc.local -> rc.d/rc.local
[root@gitlab gitlab]# echo "cd /root/gitlab && docker-compose up -d" >> /etc/rc.local
[root@gitlab gitlab]# tail -1 /etc/rc.local
cd /root/gitlab && docker-compose up -d

6)gitlab管理界面

转载www.jb51.net/article/153399.htm

地址:在浏览器输入yml文件的第12行ip或者域名
用户:root
密码:首次登陆需要手动设置密码
如下图所示:

本作品采用《CC 协议》,转载必须注明作者和本文链接
《L03 构架 API 服务器》
你将学到如 RESTFul 设计风格、PostMan 的使用、OAuth 流程,JWT 概念及使用 和 API 开发相关的进阶知识。
《L04 微信小程序从零到发布》
从小程序个人账户申请开始,带你一步步进行开发一个微信小程序,直到提交微信控制台上线发布。
讨论数量: 1

兄弟,试试我的CoreOS Docker,一键搭建环境 github.com/wenshunbiao/docker

3个月前 评论
chowjiawei (楼主) 3个月前

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!