docker搭建gitlab

docker搭建gitlab

 创建宿主机挂载目录

由于是docker镜像运行, 所以我们需要把gitlab的

配置, 数据, 日志存到容器外面, 即将其挂载到宿主机。先准备三个目录:

[root@localhost ~]# cd /srv

[root@localhost srv]# mkdir gitlab

[root@localhost srv]# cd gitlab/

[root@localhost gitlab]# ls

[root@localhost gitlab]#  mkdir config logs data

[root@localhost gitlab]# ls

config  data  logs

拉取镜像

(就使用镜像 gitlab/gitlab-ce ,其它经反复验证,不行

[root@localhost gitlab]# docker pull gitlab/gitlab-ce

Using default tag: latest

latest: Pulling from gitlab/gitlab-ce

Digest: sha256:5a0b03f09ab2f2634ecc6bfeb41521d19329cf4c9bbf330227117c048e7b5163

Status: Image is up to date for gitlab/gitlab-ce:latest

创建容器

docker run --detach --publish 443:443 --

publish 9001:80 --publish 8022:22 --

hostname 虚拟机的Ip --name mygitlab --

restart always -v

/srv/gitlab/config:/etc/gitlab -v

/srv/gitlab/logs:/var/log/gitlab -v

/srv/gitlab/data:/var/opt/gitlab -v

/etc/localtime:/etc/localtime:ro --

privileged=true gitlab/gitlab-ce

----------------------------------------------------------------------------------------------

最终执行的使用下面的,注意修改虚拟机的IP地址

docker run -di --publish 443:443 --publish 9001:80 --publish 8022:22 --hostname 192.168.99.67 --name mygitlab \

> --restart always -v \

> /srv/gitlab/config:/etc/gitlab -v \

> /srv/gitlab/logs:/var/log/gitlab -v \

> /srv/gitlab/data:/var/opt/gitlab -v \

> /etc/localtime:/etc/localtime:ro --privileged=true gitlab/gitlab-ce

run命令参数

-d, --detach: 指定容器在后台运行,默认为 false。

-e, --env: 指定环境变量。

-i:以交互模式运行容器,通常与 -t 同时使用;

-t:为容器重新分配一个伪输入终端,通常与 -i 同时使用;

-p,--publish:指定容器暴露的端口,宿主端口:容器内部端口

--name:为容器指定一个名字。

-v,--volume: 映射目录(卷),宿主目录:容器内部目录,常用来将配置文件或者是数据文件放在宿主机器上。

--restart: 指定容器停止后的重启策略:

     no: 容器退出时不重启,默认值

     no-failure: 容器故障退出(返回值为零)时重启,no-failure:3 循环重启3次。

     always: 容器退出时总是重启

--privileged:指定容器是否为特权容器,特权容器拥有所有的权限,默认为 false。

--rm:指定容器停止后自动删除容器(不支持以docker run -d 后天启动的容器),默认为 false.

(以下是我执行的情况)

[root@localhost gitlab]# docker run -di --publish 443:443 --publish 9001:80 --publish 8022:22 --hostname 192.168.99.67 --name mygitlab \

> --restart always -v \

> /srv/gitlab/config:/etc/gitlab -v \

> /srv/gitlab/logs:/var/log/gitlab -v \

> /srv/gitlab/data:/var/opt/gitlab -v \

> /etc/localtime:/etc/localtime:ro --privileged=true gitlab/gitlab-ce

01d8a25705f594e2de1e8b2abe6a2d30ef5661a5c56200fd4e02bceca199cfd4

[root@localhost gitlab]# docker ps

CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                             PORTS                                                              NAMES

01d8a25705f5        gitlab/gitlab-ce    "/assets/wrapper"   18 seconds ago      Up 18 seconds (health: starting)   0.0.0.0:443->443/tcp, 0.0.0.0:8022->22/tcp, 0.0.0.0:9001->80/tcp   mygitlab

访问gitlab

输入IP和端口直接访问  : http://192.168.99.67:9001/

用户名为: root   使用默认密码登录(下面为获取密码的方法

登录后第一时间修改密码。

获取默认密码

gitlab-ce-14初装以后,把密码放在了一个临时文件中了

/etc/gitlab/initial_root_password

这个文件将在首次执行reconfigure24小时自动删除

前面在启动容器的时候进行了挂载映射,就是为了现在查看方便。

[root@localhost gitlab]# cd /srv/gitlab/config

[root@localhost config]# cat initial_root_password

# WARNING: This value is valid only in the following conditions

#          1. If provided manually (either via `GITLAB_ROOT_PASSWORD` environment variable or via `gitlab_rails['initial_root_password']` setting in `gitlab.rb`, it was provided before database was seeded for the first time (usually, the first reconfigure run).

#          2. Password hasn't been changed manually, either via UI or via command line.

#

#          If the password shown here doesn't work, you must reset the admin password following https://docs.gitlab.com/ee/security/reset_user_password.html#reset-your-root-password.

Password: 8Ki8BhsdXmyXhd+fNG7Ox+Srp8D8TfGoAf85FhrA5Mg=

# NOTE: This file will be automatically deleted in the first reconfigure run after 24 hours.

修改密码

输入密码,点击change

修改成功,页面会跳转至登录页面,使用新密码登录

登录成功

注册新用户

 

You have signed up successfully. However, we could not sign you in because your account is awaiting approval from your GitLab administrator.

新用户登录报错解决:

使用root登录,进行审批通过就可以

刷新登录页面,重新使用新账号登录成功

502解决方案

如果虚拟机进行了重启等动作,gitlab会出现登录不上的问题,需要重新启动容器服务或者关闭防火墙。

502

Whoops, GitLab is taking too much time to respond.

Try refreshing the page, or going back and attempting the action again.

Please contact your GitLab administrator if this problem persists.

Go back

docker exec容器id  gitlab-ctl reconfigure     #容器里启动服务

防火墙根据情况来选择

systemctl stop firewalld   #关闭防火墙

将部署gitlab的容器打包成一个镜像

docker commit -a “jnc”-m “gitlab/gitlab-ce”容器ID   镜像名称:版本号

[root@localhost ~]# docker commit -a "sunsun" -m "gitlab/gitlab-ce" 01d8a25705f5 dsfzgitlab:1.0

sha256:fbd0aa8d8ae462d81a8641d6948fba35bb072ff11fed53359ef7ede7ffe60788

创建新镜像的一个容器,typecho网站正常访问

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值