docker search gitlab
docker pull gitlab/gitlab-ce
这里我们将Gitlab的配置,日志以及数据目录映射到了宿主机指定文件夹下,防止重新创建容器后丢失数据。
docker run --detach \
--publish 443:443 --publish 80:80 --publish 22:22 \
--name gitlab \
--restart always \
--volume /mydata/gitlab/config:/etc/gitlab \
--volume /mydata/gitlab/logs:/var/log/gitlab \
--volume /mydata/gitlab/data:/var/opt/gitlab \
gitlab/gitlab-ce:latest
如果本机端口443,80,22端口有被占用,则会出现如下提示,如果没有则跳过
[root@localhost config]# docker run --detach --publish 443:443 --publish 80:80 --publish 22:22 --name gitlab --restart always --volume /mydata/gitlab/config:/etc/gitlab --volume /mydata/gitlab/logs:/var/log/gitlab --volume /mydata/gitlab/data:/var/opt/gitlab gitlab/gitlab-ce:latest
f4c446ca56d3b36367cf613486c1986d09c1f1fe0dd99404db1cbbc86abbed8c
docker: Error response from daemon: driver failed programming external connectivity on endpoint gitlab (2d5155e4a0bb5edf906c1b1fb7788a8330aaf920aab6e0e170acb78bddc8d2fa): Error starting userland proxy: listen tcp 0.0.0.0:22: bind: address already in use.
如上,我远程登陆服务器,占用了22端口,那么我删除gitlab容器,将22端口映射到1022端口:
[root@localhost config]# docker run --detach --publish 443:443 --publish 80:80 --publish 1022:22 --name gitlab --restart always --volume /mydata/gitlab/config:/etc/gitlab --volume /mydata/gitlab/logs:/var/log/gitlab --volume /mydata/gitlab/data:/var/opt/gitlab gitlab/gitlab-ce:latest
docker: Error response from daemon: Conflict. The container name "/gitlab" is already in use by container "f4c446ca56d3b36367cf613486c1986d09c1f1fe0dd99404db1cbbc86abbed8c". You have to remove (or rename) that container to be able to reuse that name.
See 'docker run --help'.
[root@localhost config]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f4c446ca56d3 gitlab/gitlab-ce:latest "/assets/wrapper" 34 seconds ago Created gitlab
c72ce6edc2c0 gitlab/gitlab-ce:latest "/assets/wrapper" About an hour ago Exited (0) 3 minutes ago mygitlab
[root@localhost config]# docker rm f4c446ca56d3
f4c446ca56d3
[root@localhost config]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c72ce6edc2c0 gitlab/gitlab-ce:latest "/assets/wrapper" About an hour ago Exited (0) 3 minutes ago mygitlab
[root@localhost config]# docker run --detach --publish 443:443 --publish 80:80 --publish 1022:22 --name gitlab --restart always --volume /mydata/gitlab/config:/etc/gitlab --volume /mydata/gitlab/logs:/var/log/gitlab --volume /mydata/gitlab/data:/var/opt/gitlab gitlab/gitlab-ce:latest
4b4bfe70e0ace04dae1a9d91911037e9bbe7746221642e353b6f8171ad880d83
经过以上步骤后,等待一定时间,登陆http://ip(gitlab主机ip)后则会看到gitlab主页,但这个时候会发现clone地址不是主机IP地址,这个时候需要修改gitlab配置文件,修改host:的IP地址。
进入到容器内部,修改gitlab的配置文件:
gitlab为容器名
[root@localhost config]# docker exec -it gitlab /bin/bash
root@4b4bfe70e0ac:/# vim /opt/gitlab/embedded/service/gitlab-rails/config/gitlab.yml
保持配置文件后,重启服务:
root@4b4bfe70e0ac:/# gitlab-ctl restart
ok: run: alertmanager: (pid 1289) 0s
ok: run: gitaly: (pid 1307) 1s
ok: run: gitlab-exporter: (pid 1333) 0s
ok: run: gitlab-workhorse: (pid 1354) 1s
ok: run: grafana: (pid 1365) 0s
ok: run: logrotate: (pid 1382) 1s
ok: run: nginx: (pid 1465) 0s
ok: run: postgres-exporter: (pid 1477) 0s
ok: run: postgresql: (pid 1489) 0s
ok: run: prometheus: (pid 1498) 0s
ok: run: redis: (pid 1516) 1s
ok: run: redis-exporter: (pid 1620) 0s
ok: run: sidekiq: (pid 1629) 0s
ok: run: sshd: (pid 1636) 1s
ok: run: unicorn: (pid 1644) 0s
使用git 客户端提交代码到gitlab中时,发现每次都需要重新添加gitlab用户名和密码:
git config --global credential.helper store
这句话在会在用户目录下的.gitconfig文件最后添加:
[credential]
helper = store
这样再提交输入一次gitlab账户和密码后,就不用再次输入了。
参看地址: https://mp.weixin.qq.com/s/6GyYlR9lpVcjgYmHMYLi0w
其中把gitlab80端口映射到1080端口,这时候需要添加防火墙过滤,以及防火墙不能关闭:
# 开启1080端口
firewall-cmd --zone=public --add-port=1080/tcp --permanent
# 重启防火墙才能生效
systemctl restart firewalld
# 查看已经开放的端口
firewall-cmd --list-ports
当重定向后,登陆进入gitlab,会发现提交代码在网页无法访问,经查看为端口重定向后,访问代码文件发现访问地址默认为80端口,而不是1080端口,导致代码,以及工程文件README等文件在网页端无法访问。