1. 起因
公司里的代码管理用的还是svn,这种古老的代码库造成了代码合并是个痛苦的事情,所以急需一个靠谱的git私库关于管理小组的代码,这个时候我将目光移向了docker,毕竟方便的开箱即用不香么?
2. 安装docker
折腾了很久的ubuntu安装docker的教程,始终卡在docker的download源404问题上
root@huangssssx-TM1801:/etc/apt# add-apt-repository \
> "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
> $(lsb_release -cs) \
> stable"
命中:1 https://mirrors.ustc.edu.cn/ubuntu focal InRelease
命中:2 https://mirrors.ustc.edu.cn/ubuntu focal-security InRelease
命中:3 https://mirrors.ustc.edu.cn/ubuntu focal-updates InRelease
命中:4 https://mirrors.ustc.edu.cn/ubuntu focal-backports InRelease
忽略:5 https://download.docker.com/linux/ubuntu eoan InRelease
错误:6 https://download.docker.com/linux/ubuntu eoan Release
404 Not Found [IP: 2600:9000:202b:3000:3:db06:4200:93a1 443]
正在读取软件包列表... 完成
E: 仓库 “https://download.docker.com/linux/ubuntu eoan Release” 没有 Release 文件。
N: 无法安全地用该源进行更新,所以默认禁用该源。
N: 参见 apt-secure(8) 手册以了解仓库创建和用户配置方面的细节。
估计是咱们伟大的绿坝把我们的docker请入了404的小黑屋吧……。
后来无意中看见了一个帖子,发觉ubuntu16以后官方源是自带docker的(摔),所以直接使用官方源来安装docker咯。一次性成功~
apt-get install -y docker.io
apt-get install docker-compose
3. 然后安装git-lab
docker pull gitlab/gitlab-ce
运行git-lab
docker run -d -p 443:443 -p 80:80 -p 222:22 --name gitlab --restart always -v /home/gitlab/config:/etc/gitlab -v /home/gitlab/logs:/var/log/gitlab -v /home/gitlab/data:/var/opt/gitlab gitlab/gitlab-ce
出现下面结果说明git-lab已经跑起来了。
4. 配置
此时git-lab虽然可以使用但是仓库地址却是指向的docker容器名。比如:
http://ccfd54d888cbcaea3356ca5fdaaf1f191dcf46bc57172e73e29f3670f6cf6aea/root/test.git
这将造成我们没法拉取代码。所以我们需要配置一下git-lab的地址:
# gitlab.rb文件内容默认全是注释
$ vim /home/gitlab/config/gitlab.rb
# 配置http协议所使用的访问地址,不加端口号默认为80
external_url 'http://192.168.199.231'
# 配置ssh协议所使用的访问地址和端口
gitlab_rails['gitlab_ssh_host'] = '192.168.199.231'
gitlab_rails['gitlab_shell_ssh_port'] = 222 # 此端口是run时22端口映射的222端口
:wq #保存配置文件并退出
# 重启gitlab容器
$ docker restart gitlab
此时项目的仓库地址就变了。如果ssh端口地址不是默认的22,就会加上ssh:// 协议头
打开浏览器输入ip地址(因为我的gitlab端口为80,所以浏览器url不用输入端口号,如果端口号不是80,则打开为:ip:端口号)
5.结尾
此时已经可以愉快的使用git-lab了,访问http://localhost:80即可。