centos7下使用docker安装gitlab12.6.0

1. 配置镜像加速器

点击配置

sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://xxxxxx.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
2. 获取gitlab镜像包
[root@VM_0_6_centos data]# docker pull gitlab/gitlab-ce
Using default tag: latest
latest: Pulling from gitlab/gitlab-ce
3386e6af03b0: Pull complete
49ac0bbe6c8e: Pull complete
d1983a67e104: Pull complete
1a0f3a523f04: Pull complete
0a1871e024e9: Pull complete
22db415dc935: Pull complete
7a635a8736d3: Pull complete
cc0ef2dfa7c2: Pull complete
816bca05932d: Pull complete
9aff335224a3: Pull complete
Digest: sha256:ad3988896b5c7ccf8272bc6987ce5cff132164e9a6bfc252976b6a2a98bd4896
Status: Downloaded newer image for gitlab/gitlab-ce:latest
docker.io/gitlab/gitlab-ce:latest
[root@VM_0_6_centos data]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
gitlab/gitlab-ce    latest              939d1ad829ac        4 days ago          1.84GB
hello-world         latest              fce289e99eb9        11 months ago       1.84kB
3. 在本机准备gitlab工作目录

在本机建立的3个目录是为了gitlab容器通过挂载本机目录启动后可以映射配置文件,数据文件,日志文件到本机,然后后续就可以直接在本机查看和编辑了,不用再进容器操作。

[root@VM_0_6_centos ~]# mkdir -p /data/docker/gitlab/{config,data,logs}
4. 启动gitlab

--publish 暴露了容器的三个端口, 分别是https对应的443, http对应80以及ssh对应的22(如果不需要配置https, 可以不暴露)

--memory 限制容器最大内存暂用4G, 这是官方推荐的

--volume 指定挂载目录, 这个便于我们在本地备份和修改容器的相关数据

[root@server-10 ~]# docker run -d \
 --name gitlab \
 --hostname gitlab \
 --memory 4g \
 --restart always \
 -p 4443:443 -p 8888:80 -p 2222:22 \
 -v /data/docker/gitlab/config:/etc/gitlab \
 -v /data/docker/gitlab/data:/var/opt/gitlab \
 -v /data/docker/gitlab/logs:/var/log/gitlab \
 gitlab/gitlab-ce:latest
5. 检查启动信息
[root@VM_0_6_centos data]# docker ps
CONTAINER ID        IMAGE                     COMMAND             CREATED             STATUS                             PORTS                                                               NAMES
e9fbcdb96669        gitlab/gitlab-ce:latest   "/assets/wrapper"   29 seconds ago      Up 28 seconds (health: starting)   0.0.0.0:2222->22/tcp, 0.0.0.0:8888->80/tcp, 0.0.0.0:4443->443/tcp   gitlab

启动需要一段时间(注意STATUS)

[root@VM_0_6_centos data]# docker ps
CONTAINER ID        IMAGE                     COMMAND             CREATED             STATUS                   PORTS                                                               NAMES
e9fbcdb96669        gitlab/gitlab-ce:latest   "/assets/wrapper"   4 minutes ago       Up 4 minutes (healthy)   0.0.0.0:2222->22/tcp, 0.0.0.0:8888->80/tcp, 0.0.0.0:4443->443/tcp   gitlab

查看本机端口状态

[root@VM_0_6_centos data]# netstat -tnl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN
tcp6       0      0 :::2222                 :::*                    LISTEN
tcp6       0      0 :::8888                 :::*                    LISTEN
tcp6       0      0 :::4443                 :::*                    LISTEN

查看本机为gitlab容器新建的工作目录内容

[root@VM_0_6_centos ~]# tree -L 2 /data/docker/gitlab/
/data/docker/gitlab/
├── config
│   ├── gitlab.rb
│   ├── gitlab-secrets.json
│   ├── ssh_host_ecdsa_key
│   ├── ssh_host_ecdsa_key.pub
│   ├── ssh_host_ed25519_key
│   ├── ssh_host_ed25519_key.pub
│   ├── ssh_host_rsa_key
│   ├── ssh_host_rsa_key.pub
│   └── trusted-certs
├── data
│   ├── alertmanager
│   ├── backups
│   ├── bootstrapped
│   ├── gitaly
│   ├── git-data
│   ├── gitlab-ci
│   ├── gitlab-exporter
│   ├── gitlab-rails
│   ├── gitlab-shell
│   ├── gitlab-workhorse
│   ├── grafana
│   ├── logrotate
│   ├── nginx
│   ├── postgres-exporter
│   ├── postgresql
│   ├── prometheus
│   ├── public_attributes.json
│   ├── redis
│   └── trusted-certs-directory-hash
└── logs
    ├── alertmanager
    ├── gitaly
    ├── gitlab-exporter
    ├── gitlab-rails
    ├── gitlab-shell
    ├── gitlab-workhorse
    ├── grafana
    ├── logrotate
    ├── nginx
    ├── postgres-exporter
    ├── postgresql
    ├── prometheus
    ├── reconfigure
    ├── redis
    ├── redis-exporter
    ├── sidekiq
    ├── sshd
    └── unicorn

38 directories, 11 files
6. 登录gitlab
7. 设置邮件服务
服务器名称 服务器地址 SSL协议端口号 非SSL协议端口号
SMTP smtp.163.com 465/994 25

smtp_port对应的端口25可能被阿里云或腾讯云封禁,需要申请解禁

[root@VM_0_6_centos ~]# vi /data/docker/gitlab/config/gitlab.rb
    user['git_user_email'] = "[email protected]"
    gitlab_rails['gitlab_email_enabled'] = true
    gitlab_rails['gitlab_email_from'] = '[email protected]'
    gitlab_rails['smtp_enable'] = true
    gitlab_rails['smtp_address'] = "smtp.163.com"
    gitlab_rails['smtp_port'] = 465
    gitlab_rails['smtp_user_name'] = "[email protected]"
    gitlab_rails['smtp_password'] = "xxxxx"
    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['smtp_openssl_verify_mode'] = 'none'

重新配置服务、测试

root@gitlab:/# ggitlab-ctl reconfigure
root@gitlab:/# gitlab-ctl restart
root@gitlab:/# gitlab-rails console
--------------------------------------------------------------------------------
 GitLab:       12.6.0-ee (fc376e40baf)
 GitLab Shell: 10.3.0
 PostgreSQL:   10.9
--------------------------------------------------------------------------------
Loading production environment (Rails 5.2.3)
irb(main):001:0> Notify.test_email('[email protected]','title','lalalalalallalalalaalalalal').deliver_now
Notify#test_email: processed outbound mail in 1.9ms
Sent mail to [email protected] (604.3ms)
Date: Thu, 26 Dec 2019 01:59:31 +0000
From: GitLab 
Reply-To: GitLab 
To: [email protected]
Message-ID: <[email protected]>
Subject: title
Mime-Version: 1.0
Content-Type: text/html;
 charset=UTF-8
Content-Transfer-Encoding: 7bit
Auto-Submitted: auto-generated
X-Auto-Response-Suppress: All


lalalalalallalalalaalalalal

=> #, >, >, , >, , , , , , >

参考

centos7下使用docker安装gitlab

Docker部署GitLab

Gitlab的邮箱配置和使用

腾讯云服务器使用smtp发送邮件

你可能感兴趣的:(centos7下使用docker安装gitlab12.6.0)