1、拉取镜像
docker pull gitlab/gitlab-ce:latest
2、启动Gitlab容器
# 启动容器
docker run -itd \
-p 9980:80 \
-p 9922:22 \
-v /myDocker/gitlab/etc:/etc/gitlab \
-v /myDocker/gitlab/log:/var/log/gitlab \
-v /myDocker/gitlab/opt:/var/opt/gitlab \
--restart always \
--privileged=true \
--name gitlab \
gitlab/gitlab-ce
- -i ** 以交互模式运行容器,通常与 -t 同时使用命令解释**
- -t ** 为容器重新分配一个伪输入终端,通常与 -i 同时使用**
- -d 后台运行容器,并返回容器ID
- -p 9980:80 将容器内80端口映射至宿主机9980端口,这是访问gitlab的端口
- -p 9922:22 ** 将容器内22端口映射至宿主机9922端口,这是访问ssh的端口**
- -v /myDocker/gitlab/etc:/etc/gitlab 将容器/etc/gitlab目录挂载到宿主机/myDocker/gitlab/etc目录下,若宿主机内此目录不存在将会自动创建,其他两个挂载同这个一样
- --restart always 容器自启动
- --privileged=true 让容器获取宿主机root权限
- --name gitlab 设置容器名称为gitlab
- gitlab/gitlab-ce 镜像的名称,这里也可以写镜像ID
3、修改配置
#进容器内部
docker exec -it gitlab /bin/bash
#修改gitlab.rb
vi /etc/gitlab/gitlab.rb
#加入如下
#gitlab访问地址,可以写域名。如果端口不写的话默认为80端口
external_url 'http://192.168.10.101'
#ssh主机ip
gitlab_rails['gitlab_ssh_host'] = '192.168.10.101'
#ssh连接端口
gitlab_rails['gitlab_shell_ssh_port'] = 9922
# 让配置生效
gitlab-ctl reconfigure
4、登陆
用户名:root
初始密码:见文件/myDocker/gitlab/etc/ssh_host_ecdsa_key
5、精简gitlab
修改/myDocker/gitlab/etc/gitlab.rb
# 关闭容器仓库功能
gitlab_rails['gitlab_default_projects_features_container_registry'] = false
gitlab_rails['registry_enabled'] = false
registry['enable'] = false
registry_nginx['enable'] = false
# 包仓库、依赖管理
gitlab_rails['packages_enabled'] = false
gitlab_rails['dependency_proxy_enabled'] = false
# GitLab Pages
gitlab_pages['enable'] = false
pages_nginx['enable'] = false
# 关闭监控和性能基准相关功能
prometheus_monitoring['enable'] = false
alertmanager['enable'] = false
node_exporter['enable'] = false
redis_exporter['enable'] = false
postgres_exporter['enable'] = false
pgbouncer_exporter['enable'] = false
gitlab_exporter['enable'] = false
grafana['enable'] = false
sidekiq['metrics_enabled'] = false
# Usage Statistics
gitlab_rails['usage_ping_enabled'] = false
gitlab_rails['sentry_enabled'] = false
grafana['reporting_enabled'] = false
# GitLab KAS
gitlab_kas['enable'] = false
gitlab_rails['gitlab_kas_enabled'] = false
# Terraform
gitlab_rails['terraform_state_enabled'] = false
# Kerberos 文档说EE only,但是默认值为 true
gitlab_rails['kerberos_enabled'] = false
# Sentinel
sentinel['enable'] = false
# Mattermost
mattermost['enable'] = false
mattermost_nginx['enable'] = false
# 禁用 PUMA 集群模式
puma['worker_processes'] = 0
puma['min_threads'] = 1
puma['max_threads'] = 2
# 降低后台守护进程并发数
sidekiq['max_concurrency'] = 3
gitlab_ci['gitlab_ci_all_broken_builds'] = false
gitlab_ci['gitlab_ci_add_pusher'] = false
修改生效
gitlab-ctl reconfigure
gitlab-ctl restart
docker生效方式:
重载配置:docker exec -it gitlab gitlab-ctl reconfigure
重启:docker exec -it gitlab gitlab-ctl restart