Docker 搭建GitLab

拉取镜像

cpp 复制代码
docker pull gitlab/gitlab-ce

GitLab 需要持久存储来保存数据,如仓库数据、配置

cpp 复制代码
mkdir -p /opt/gitlab/config /opt/gitlab/logs /opt/gitlab/data

使用 docker run 命令来启动 GitLab 容器

cpp 复制代码
docker run -itd \
  --hostname 192.168.111.128 \
  --publish 443:443 \
  --publish 80:80 \
  --publish 2222:22 \
  --name gitlab \
  --restart always \
  --volume /opt/gitlab/config:/etc/gitlab \
  --volume /opt/gitlab/logs:/var/log/gitlab \
  --volume /opt/gitlab/data:/var/opt/gitlab \
  gitlab/gitlab-ce:latest

解释命令参数说明:

--detach: 让容器在后台运行(-itd 是 -it -d 的结合,--detach = -d)。

--hostname your-gitlab-hostname: 替换为你的 GitLab 主机名或域名。

--publish 443:443 --publish 80:80 --publish 22:22: 将容器内部的 443(HTTPS)、80(HTTP)和 22(SSH)端口映射到主机的对应端口,允许外部访问 GitLab。

--name gitlab: 指定容器的名称为 gitlab。

--restart always: 容器在退出后始终自动重启。

--volume /opt/gitlab/config:/etc/gitlab: 将主机上的 /opt/gitlab/config 目录挂载到容器内的 /etc/gitlab,用于存储 GitLab 的配置文件。

--volume /opt/gitlab/logs:/var/log/gitlab: 将主机上的 /opt/gitlab/logs 目录挂载到容器内的 /var/log/gitlab,用于存储 GitLab 的日志文件。

--volume /opt/gitlab/data:/var/opt/gitlab: 将主机上的 /opt/gitlab/data 目录挂载到容器内的 /var/opt/gitlab,用于存储 GitLab 的数据(如仓库数据、上传文件等)。

启动时间比较久,耐心等3-5分钟,此时可以查看启动日志

Docker 容器日志查看

cpp 复制代码
docker logs gitlab

如果你访问的页面没提示设置root管理员的密码,需要自己修改

修改密码步骤:

cpp 复制代码
# 进入 GitLab 容器或服务器(gitlab_container_name 容器ID)
	docker exec -it <gitlab_container_name> /bin/bash
	
	# 重置管理员密码
	gitlab-rails console -e production
	
	# 在控制台中重置密码
	user = User.where(id: 1).first
	user.password = 'chengdong'
	user.password_confirmation = 'chengdong'
	user.save!
	
	# exit 退出控制台并重启 GitLab
	gitlab-ctl restart

登录成功之后设置 中文

中间显示 Configure GitLab ==> Settings ==> Preferences ==> Localization 或者上面直接搜索:Default language root账户只能英文,创建新的账户登录就是中文了

cpp 复制代码
# 修改gitlab的下载代码的路径地址,修改gitlab主配置文件
#/opt/gitlab/config/gitlab.rb
修改:
external_url 'http://192.168.111.128'

重启容器

cpp 复制代码
docker restart gitlab
相关推荐
咚咚?1 小时前
基于gitlab 构建CICD发布到K8S 平台
容器·kubernetes·gitlab
尘土哥4 小时前
Docker 快速上手
docker·容器·eureka
广州山泉婚姻5 小时前
Docker从环境配置到应用上云的极简路径
docker
胡耀超9 小时前
Umi-OCR 的 Docker安装(win制作镜像,Linux(Ubuntu Server 22.04)离线部署)
linux·深度学习·ubuntu·docker·容器·nlp·ocr
铃木隼.13 小时前
docker容器高级管理-dockerfile创建镜像
运维·docker·容器
容器魔方13 小时前
持续领跑,华为云连续5年蝉联中国容器软件市场份额第一
云原生·容器·云计算
开开心心就好16 小时前
AI抠图软件,本地运行超快速
网络·人工智能·网络协议·tcp/ip·docker·电脑·excel
IT成长日记19 小时前
【Docker基础】Dockerfile指令速览:文件与目录操作指令详解
docker·容器·volume·add·dockerfile·workdir
胡耀超19 小时前
GraphRAG Docker化部署,接入本地Ollama完整技术指南:从零基础到生产部署的系统性知识体系
运维·docker·容器·大模型·知识图谱·rag·ollama