1.pull中文版镜像:
docker pull beginor/gitlab-ce:11.3.0-ce.0
2.创建目录:
通常会将 GitLab 的配置 (etc) 、 日志 (log) 、数据 (data) 放到容器之外, 便于日后升级, 因此请先准备这三个目录。
mkdir -p /usr/local/gitlab/etc
mkdir -p /usr/local/gitlab/log
mkdir -p /usr/local/gitlab/data
3.修改目录权限:
chmod 777 /usr/local/gitlab/etc
chmod 777 /usr/local/gitlab/log
chmod 777 /usr/local/gitlab/data
4.运行:
准备好这三个目录之后, 就可以开始运行 Docker 镜像了:
docker run --detach --publish 8443:443 --publish 8888:80 --publish 8222:22 --name gitlab --restart unless-stopped --volume /usr/local/gitlab/etc:/etc/gitlab --volume /usr/local/gitlab/log:/var/log/gitlab --volume /usr/local/gitlab/data:/var/opt/gitlab --privileged=true beginor/gitlab-ce:11.3.0-ce.0
--publish 8443:443:将http:443映射到外部端口8443
--publish 8888:80:将web:80映射到外部端口8888
--publish 8222:22:将ssh:22映射到外部端口8222
--name gitlab 运行容器名
--restart unless-stopped 重启策略
--volume /usr/local/gitlab/etc:/etc/gitlab 挂载目录
--volume /usr/local/gitlab/log:/var/log/gitlab 挂载目录
--volume /usr/local/gitlab/data:/var/opt/gitlab 挂载目录
--privileged=true 使得容器内的root拥有真正的root权限。否则,container内的root只是外部的一个普通用户权限
5.访问:
稍等片刻,初始化完毕,再打开浏览器:ip地址:8888 (http://192.168.2.212:8888/)
修改密码为:123456789,修改完成:使用 用户名root,密码为123456789进行登陆。
邮件发送配置:
cd /usr/local/gitlab/etc 跳转至挂载目录
vim gitlab.rb
开启qq邮箱的POP3/SMTP服务并保存好授权码:
在gitlab.rb末尾加上:
gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.qq.com"
gitlab_rails['smtp_port'] = 465
gitlab_rails['smtp_user_name'] = "1066394274@qq.com"
gitlab_rails['smtp_password'] = "授权码"
gitlab_rails['smtp_domain'] = "smtp.qq.com"
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_enable_starttls_auto'] = true
gitlab_rails['smtp_tls'] = true
gitlab_rails['gitlab_email_from'] = '1066394274@qq.com'
进入容器内部:
docker exec -it gitlab bash
重启生效:
gitlab-ctl reconfigure
测试配置是否成功:
gitlab-rails console 进入控制台
Notify.test_email('1107592245', '邮件标题', '邮件正文').deliver_now 向测试邮箱发送测试邮件
发送测试邮件:
发现有一封新的邮件:
点击链接:
此处将
http://d7136f987efd/users/confirmation?confirmation_token=KWEVNipWBy2DjkFji4-X
d7136f987efd 置换为 192.168.2.212:8080
访问之后,激活成功。
生成SSH私钥:
[root@localhost ~]# ssh-keygen -o -t rsa -C "1066394274@qq.com" -b 4096
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:DYH3I8KhprEb/N6E0ErkR+Chjes4rwo1orSqhrtOCBE 1066394274@qq.com
The key's randomart image is:
+---[RSA 4096]----+
|E o .. |
| * o o .. |
|+ + .o o.. |
| =.oo o .oo |
|+o*=o .S... |
|B+*= . |
|B+.+. . |
|=+. .o |
|%=... . |
+----[SHA256]-----+
[root@localhost ~]# cat ~/.ssh/id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDSMr3ihBbSbjXQaJTjxBNiMpExUMz0J4LZ/2xCxYpUWvQs/9pmbhCl7Do9Y8TbebBy3yxUVINB8yIqgKwsX3XnXsE3TEHXKI+/dbrjlxhK49dghT6kyJwsCE1fQ4JbUz8cX7WsYysuOR326Wajdud+e14KGuuozV3ooAfmhBnTqEvj7PULCOMsLD1bftMmNvbeVRW4KSE7wWrdGurD3v5gAPMhfDDAs72g8qApsW0nyunnMd+OyQRtsD7V+y5Tlk3f1pnEE2yTXxYg5REHQhMyrfoH+MHGAHQH226sFQ106Y8IiJPIAs4zL9CTkiz4dPsOmpzyTt5f7RjJhyLUI0rM5StkZsu/bbchgMppQK4/CZtg/rBIygRB0zmisgdDZA2kpfvPmM7MCBFrYdIuutz/HjIkyg8+RnvTDEo0CBgbs1X0Nm3zL7P6MB6RlW4Zsz5fSrn49FH3pylyR2wkkebd86L53p+3117SrBH2FQEYsgwYGpcOBv8ZC3w25+7/ExrCoyx6VRbf4bqsyZ7gsX8sAHsRlEeCpiI1kGZXvYJj5jFoaq3zsDTEwn6miQINJYJVIhOnPUsDHxK7IHLu2Grd/W6EtZaLJ1je4xXpgdMDMe7/HM8rZ0RPXP90xkg/7hXmGLxd+exlp1t9GkjZ5ogQ2ZSyBSMt5oN5oGzUEBjLeQ== 1066394274@qq.com
项目path错误:
docker exec -it gitlab vim /etc/gitlab/gitlab.rb
修改为当前服务器ip;停止删除容器:
docker stop gitlab
docker rm gitlab
重启系统:
reboot
运行容器:
docker run --detach --publish 8443:443 --publish 8888:8888 --publish 8222:22 --name gitlab --restart unless-stopped --volume /usr/local/gitlab/etc:/etc/gitlab --volume /usr/local/gitlab/log:/var/log/gitlab --volume /usr/local/gitlab/data:/var/opt/gitlab --privileged=true beginor/gitlab-ce:11.3.0-ce.0
将内部端口号从80改为和外部端口一致的8888
此时,使用http和ssh拉取,均能成功:
升级
小版本升级(例如从 8.8.2 升级到 8.8.3), 参照官方的说明, 将原来的容器停止, 然后删除:
docker stop gitlab
docker rm gitlab
然后重新拉一个新版本的镜像下来:
docker pull beginor/gitlab-ce:11.3.0-ce.0
还使用原来的运行命令运行:
docker run
--detach
--publish 8443:443
--publish 8080:80
--name gitlab
--restart unless-stopped
--volume /mnt/sda1/gitlab/etc:/etc/gitlab
--volume /mnt/sda1/gitlab/log:/var/log/gitlab
--volume /mnt/sda1/gitlab/data:/var/opt/gitlab
beginor/gitlab-ce:11.3.0-ce.0
大版本升级(例如从 8.7.x 升级到 8.8.x)用上面的操作有可能会出现错误, 如果出现错误可以尝试登录到容器内部, 可以用 docker exec
, 也可以用 ssh , 依次执行下面的命令:
gitlab-ctl reconfigure
gitlab-ctl restart
错误处理:
docker 容器提示没安装vim:
apt-get update
apt-get install vim
停止所有的container:
docker stop $(docker ps -a -q)
删除所有container:
docker rm $(docker ps -a -q)