docker pull gitlab/gitlab-ce:15.1.6-ce.0

docker run -d --name gitlab-15.1.6 --hostname localhost -p 8090:80 -p 8443:443 -p 2222:22 --restart unless-stopped --shm-size 256m gitlab/gitlab-ce:15.1.6-ce.0

获取密码

# 2分钟后先试试
docker exec gitlab-15.1.6 cat /etc/gitlab/initial_root_password

# 如果显示文件不存在,等待并重试
# 等看到日志显示 "gitlab Reconfigured!" 后再试

因为在 8090 端口访问,需要配置 GitLab:

# 进入容器
docker exec -it gitlab-15.1.6 bash

# 编辑配置文件
vi /etc/gitlab/gitlab.rb

# 添加以下配置:
external_url 'http://localhost:8090'  # 重要:指定你的端口
nginx['listen_port'] = 80
nginx['listen_https'] = false
gitlab_rails['gitlab_shell_ssh_port'] = 2222
gitlab_rails['gitlab_https'] = false

# 保存并退出(vi: 按 Esc,输入 :wq,回车)

# 重新配置
gitlab-ctl reconfigure

# 重启服务
gitlab-ctl restart

# 退出容器
exit

# 配置全局用户信息
git config --global user.name "你的名字"
git config --global user.email "你的邮箱@example.com"

# 克隆项目时使用正确的 URL
git clone http://localhost:8090/username/project.git
# 或使用 SSH(注意端口)
git clone ssh://git@localhost:2222/username/project.git

验证:

# 测试 HTTP 连接
curl http://localhost:8090

# 如果 curl 不可用,用 PowerShell
Invoke-WebRequest -Uri "http://localhost:8090" -Method Get

更多推荐