DevOps实战(一)使用Docker搭建Gitlab社区版

什么是DevOps?

DevOps的哲学暂且不表,本文主要介绍如何使用Docker搭建Gitlab。

关键词:gitlab

前言

docker作为快速部署应用的方式已经迅速流行起来,极大的解放了运维人员的工作。

安装

下载镜像

1
docker pull gitlab/gitlab-ce:latest

docker-compose部署文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
version: '3.6'
services:
gitlab:
image: 'gitlab/gitlab-ee:latest'
# image: registry.gitlab.cn/omnibus/gitlab-jh:latest
container_name: gitlab
restart: always
hostname: 'gitlab.lo' # ssh hostname
environment:
GITLAB_OMNIBUS_CONFIG: |
external_url 'https://gitlab.lo' # git httpsname
nginx['redirect_http_to_https'] = false
nginx['listen_port'] = 8880
nginx['listen_https'] = false
prometheus_monitoring['enable'] = false
ports:
- '127.0.0.1:8880:8880'
- '22:22'
volumes:
- './config:/etc/gitlab'
- './logs:/var/log/gitlab'
- './data:/var/opt/gitlab'
shm_size: '256m'
privileged: true

Nginx反向代理文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
 server {
charset utf-8;
#listen unix:/dev/shm/default.sock proxy_protocol;
#listen unix:/dev/shm/h2c.sock http2 proxy_protocol;
listen 443 ssl;
server_tokens off;
server_name gitlab.lo;
ssl_session_cache shared:SSL:10m;
ssl_certificate /ssl/gitlab.lo.crt;
ssl_certificate_key /ssl/gitlab.lo.key;

#ssl_stapling on;
#ssl_stapling_verify on;

ssl_session_timeout 10m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
location / {
#proxy_redirect off;
#proxy_pass https://wf09.github.io/;
#alias /home/ubuntu/tmp/;
proxy_pass http://127.0.0.1:8880;
proxy_set_header Host $host; # required for docker client's sake
proxy_set_header X-Real-IP $remote_addr; # pass on real client's IP
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}

其他操作

查看root用户密码

1
docker exec -it gitlab grep 'Password:' /etc/gitlab/initial_root_password