1. Gitlab image pull
The latest version is $docker pull gitlab/gitlab-ceCopy the code
2. Create a mapping folder
$ sudo mkdir -p /home/gitlab/etc
$ sudo mkdir -p /home/gitlab/log
$ sudo mkdir -p /home/gitlab/dataCopy the code
3. Run the container
Docker run --detach --publish 8001:80 --publish 8002:22 --publish 8001:80 Publish 8003:443 # publish 8003:443 # --name gitlab \ --restart unless-stopped \ --hostname gitlab.yuezhisan.com \ If it is a public host can write domain name - v/home/gitlab/etc, / etc/gitlab \ # mount gitlab configuration file - v/home/gitlab/log: / var/log/gitlab \ # mount gitlab log file - v / home/gitlab/data: / var/opt/gitlab \ # mount gitlab data - v/etc/localtime: / etc/localtime: ro \ # keep hosting and container time synchronization - ring = true Gitlab /gitlab-ce # Can perform operations as root in the containerCopy the code
4. Modify the configuration file to support HTTPS
1) Download the placement certificate
Tencent cloud or Ali cloud download free certificate, after decompression
gitlab.yuezhisan.com.key
: Certificate private keygitlab.yuezhisan.com.crt
: public key; Tencent provides CRT, ali Cloud provides PEM format
Create an SSL folder under /home/gitlab/etc and copy the certificate in the folder. Only CRT format is supported
2) Configure the gitlab.rb file
Remove the configuration item comment # and modify some of the content
29 external_url 'https://gitlab.yuezhisan.com'
1207 nginx['enable'] = true
1208 nginx['client_max_body_size'] = '250m'
1209 nginx['redi1210rect_http_to_https'] = true
1210 nginx['redirect_http_to_https_port'] = 80
1221 nginx['ssl_certificate'] = "/etc/gitlab/ssl/gitlab.yuezhisan.com.crt"
1222 nginx['ssl_certificate_key'] = "/etc/gitlab/ssl/gitlab.yuezhisan.com.key"
1262 nginx['proxy_set_headers'] = {
"Host" => "$http_host_with_default",
"X-Real-IP" => "$remote_addr",
"X-Forwarded-For" => "$proxy_add_x_forwarded_for",
"X-Forwarded-Proto" => "https",
"X-Forwarded-Ssl" => "on",
"Upgrade" => "$http_upgrade",
"Connection" => "$connection_upgrade"
}Copy the code
Docker restart Gitlab container