Docker部署配置Gitlab
采用Docker部署
# 拉取镜像
docker pull gitlab/gitlab-ce
# 查看镜像
docker images | grep gitlab
# 应该能看到类似输出:
gitlab/gitlab-ce latest [镜像ID] [大小] [创建时间]
# 创建目录
mkdir -p /data/gitlab/{config,logs,data}
# 关键步骤:将目录所有者改为容器内的 git 用户 (UID 998)
chown -R 998:998 /data/gitlab
# 检查端口没有被占用
ss -tlnp | grep -E '8443|8099|8222'
# 启动容器(注意根据你的需求修改端口映射和目录)
docker run --publish 8443:443 --publish 8099:80 --publish 8222:22 \
--name gitlab --restart unless-stopped \
--volume /data/gitlab/config:/etc/gitlab \
--volume /data/gitlab/logs:/var/log/gitlab \
--volume /data/gitlab/data:/var/opt/gitlab \
-d gitlab/gitlab-ce获取 root 密码
# 获取密码
docker exec -it gitlab cat /etc/gitlab/initial_root_password
# 显示内容
# WARNING: This password is only valid if ALL of the following are true:
# • You set it manually via the GITLAB_ROOT_PASSWORD environment variable
# OR the gitlab_rails['initial_root_password'] setting in /etc/gitlab/gitlab.rb
# • You set it BEFORE the initial database setup (typically during first installation)
# • You have NOT changed the password since then (via web UI or command line)
#
# If this password doesn't work, reset the admin password using:
# https://docs.gitlab.com/security/reset_user_password/#reset-the-root-password
Password: PYua4FSiAd/GeogLoa5bPbTPoY75yKjVSTHf+Y2hkUc=
# NOTE: This file is automatically deleted after 24 hours on the next reconfigure run.访问 GitLab
# 浏览器打开:
http://192.168.7.120:8099
# 用户名:
root
# 密码:
PYua4FSiAd/GeogLoa5bPbTPoY75yKjVSTHf+Y2hkUc=
# 首次登录
登录后会提示修改密码,按提示操作即可常用管理命令
# 停止 GitLab
docker stop gitlab
# 启动 GitLab
docker start gitlab
# 重启 GitLab
docker restart gitlab
# 查看日志
docker logs -f gitlab
# 查看服务状态
docker exec -it gitlab gitlab-ctl status
# 进入容器内部
docker exec -it gitlab bash修改配置(如需要)
如果后续需要修改域名或端口:
# 编辑配置文件
vi /data/gitlab/config/gitlab.rb
# 例如修改外部 URL
external_url 'http://你的域名或IP:8099'
# 应用配置
docker exec -it gitlab gitlab-ctl reconfigure
# 重启容器
docker restart gitlab
原创
Docker部署配置Gitlab
本文采用 CC BY-NC-SA 4.0 许可协议,转载请注明出处。
评论交流
欢迎留下你的想法