官方教程
https://docs.gitlab.com/omnibus/docker/
建议虚拟机内存2G以上
1.下载镜像文件
docker pull beginor/gitlab-ce:11.0.1-ce.0
注意:一定要配置阿里云的加速镜像
mkdir -p /mnt/gitlab/etc mkdir -p /mnt/gitlab/log mkdir -p /mnt/gitlab/data
运行GitLab容器
docker run --detach --publish 8443:443 --publish 8090:80 --name gitlab --restart unless-stopped -v /mnt/gitlab/etc:/etc/gitlab -v /mnt/gitlab/log:/var/log/gitlab -v /mnt/gitlab/data:/var/opt/gitlab beginor/gitlab-ce:11.0.1-ce.0
停止docker容器,并且删除
docker stop 容器id
docker rm 容器id
systemctl stop firewalld
将挂载文件同步到容器外面
[root@localhost ~]# docker run > --detach nor/gitlab-ce:11.0.1-ce.0 > --publish 8443:443 > --publish 8090:80 > --name gitlab > --restart unless-stopped > -v /mnt/gitlab/etc:/etc/gitlab > -v /mnt/gitlab/log:/var/log/gitlab > -v /mnt/gitlab/data:/var/opt/gitlab > beginor/gitlab-ce:11.0.1-ce.0 7079a63817279290899e21046f75d64a1e636087afbd510545212a242bef62b4 docker: Error response from daemon: driver failed programming external connectivity on endpoint gitlab
(0e14a81954fa738bcf42b5f67bd3c2ad4f11413f9cd28ec58efb98a9a8414ae4):
(iptables failed: iptables --wait -t nat -A DOCKER -p tcp -d 0/0 --dport 8443 -j DNAT --to-destination
172.17.0.3:443 ! -i docker0: iptables: No chain/target/match by that name.
直接运行会报一个错误,报错我们先把容器停掉,然后删除
[root@localhost ~]# docker stop 7079a63817279290899e21046f75d64a1e636087afbd510545212a242bef62b4 7079a63817279290899e21046f75d64a1e636087afbd510545212a242bef62b4 [root@localhost ~]# docker rm 7079a63817279290899e21046f75d64a1e636087afbd510545212a242bef62b4 7079a63817279290899e21046f75d64a1e636087afbd510545212a242bef62b4
这样就已经删除成功了,然后我们再来看一看之前报错的问题,谷歌一下
将这段拿出来搜索一下,全部搜索肯定不行
Error response from daemon:
driver failed programming external connectivity on endpoint gitlab
No chain/target/match by that name.
最总找到了这篇文章
https://blog.csdn.net/qq_42114918/article/details/81840335
[root@localhost ~]# systemctl daemon-reload
[root@localhost ~]# systemctl restart docker.service
我猜测应该daemon的问题,我们再来试一下
[root@localhost ~]# docker run > --detach > --publish 8443:443 > --publish 8090:80 > --name gitlab > --restart unless-stopped > -v /mnt/gitlab/etc:/etc/gitlab > -v /mnt/gitlab/log:/var/log/gitlab > -v /mnt/gitlab/data:/var/opt/gitlab > beginor/gitlab-ce:11.0.1-ce.0 3f3d49ac7888aaf51d51761c27f92e4bf1b465f76b1a58f3428637b9c3ffd9b7 [root@localhost ~]#
这次没有报错了,直接就成功了。
这个时候我们进到目录再看一下挂载文件是否同步到外面来了
[root@localhost ~]# cd /mnt/gitlab/etc/ [root@localhost etc]# ls gitlab.rb ssh_host_ecdsa_key ssh_host_ed25519_key ssh_host_rsa_key trusted-certs gitlab-secrets.json ssh_host_ecdsa_key.pub ssh_host_ed25519_key.pub ssh_host_rsa_key.pub
修改/mnt/gitlab/etc/gitlab.rb
把external_url改成部署机器的域名或者IP地址
vi /mnt/gitlab/etc/gitlab.rb
external_url ‘http://192.168.56.3‘
按 i 进行编辑,编辑好了按Esc,:wq 进行保存
修改/mnt/gitlab/data/gitlab-rails/etc/gitlab.yml
vi /mnt/gitlab/data/gitlab-rails/etc/gitlab.yml
找到关键字 * ## Web server settings *
按斜杠进行搜索
/Web server settings
这个时候我们把容器停止再删除,然后重启服务
[root@localhost ~]# docker stop 3f3d49ac7888aaf51d51761c27f92e4bf1b465f76b1a58f3428637b9c3ffd9b7 3f3d49ac7888aaf51d51761c27f92e4bf1b465f76b1a58f3428637b9c3ffd9b7 [root@localhost ~]# docker rm 3f3d49ac7888aaf51d51761c27f92e4bf1b465f76b1a58f3428637b9c3ffd9b7 3f3d49ac7888aaf51d51761c27f92e4bf1b465f76b1a58f3428637b9c3ffd9b7 [root@localhost ~]# systemctl restart docker [root@localhost ~]#
再来重新创建容器
[root@localhost ~]# docker run > --detach > --publish 8443:443 > --publish 8090:80 > --name gitlab > --restart unless-stopped > -v /mnt/gitlab/etc:/etc/gitlab > -v /mnt/gitlab/log:/var/log/gitlab > -v /mnt/gitlab/data:/var/opt/gitlab > beginor/gitlab-ce:11.0.1-ce.0 d07898b3749d72870eed634a8ce9d371c981a5b962596fff76d59fc3e8c164d6 [root@localhost ~]#
这个时候我们来查一下,看一下容器有没有分配ip地址,有的话表示创建容器成功了。
[root@localhost ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES d07898b3749d beginor/gitlab-ce:11.0.1-ce.0 "/assets/wrapper" About a minute ago Up Less than a second (health: starting) 22/tcp, 0.0.0.0:8090->80/tcp, 0.0.0.0:8443->443/tcp gitlab f264e5f1be41 sonatype/nexus3 "sh -c ${SONATYPE_DI…" 2 hours ago Up 2 hours 0.0.0.0:8081->8081/tcp nexus [root@localhost ~]# docker inspect d07898b3749d
访问一下ip地址
[root@localhost ~]# curl 172.17.0.3:80
curl: (7) Failed connect to 172.17.0.3:80; Connection refused
拒绝连接,说明启动没有那么快,还需要一些时间
关闭防火墙,查看下状态,这个时候防火墙已经关闭了。
[root@localhost ~]# systemctl stop firewalld.service [root@localhost ~]# firewall-cmd --state not running [root@localhost ~]#
查看了下容器状态,发现gitlab一直是重启状态,没办法,删掉重新来
[root@localhost ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUSPORTS NAMES
d07898b3749d beginor/gitlab-ce:11.0.1-ce.0 "/assets/wrapper" 19 minutes ago Restarting (1) 1 second ago gitlab
再次创建,
docker run -d -h gitlab -p 2222:22 -p 8090:80 -p 8443:443 -v /mnt/gitlab/etc:/etc/gitlab -v /mnt/gitlab/log:/var/log/gitlab -v /mnt/gitlab/data:/var/opt/gitlab --restart always --name gitlab beginor/gitlab-ce:11.0.1-ce.0
创建成功
[root@localhost ~]# docker run -d > -h gitlab > -p 2222:22 > -p 8090:80 > -p 8443:443 > -v /mnt/gitlab/etc:/etc/gitlab > -v /mnt/gitlab/log:/var/log/gitlab > -v /mnt/gitlab/data:/var/opt/gitlab > --restart always > --name gitlab > beginor/gitlab-ce:11.0.1-ce.0 cd44b12ccb78e582b01ce35c8c9f7a3d920cfcfa86bff1f56fc85fc11af014df [root@localhost ~]#
重新来一遍之后,发现还不行
我们换个镜像再试试,可能这个版本的gitlab有问题
先停止容器删除容器,再删除镜像
[root@localhost ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE sonatype/nexus3 latest 36b0df681a47 12 days ago 582MB beginor/gitlab-ce 11.0.1-ce.0 e76a6ec6e22e 12 months ago 1.61GB [root@localhost ~]# docker stop cd44b12ccb78e582b01ce35c8c9f7a3d920cfcfa86bff1f56fc85fc11af014df cd44b12ccb78e582b01ce35c8c9f7a3d920cfcfa86bff1f56fc85fc11af014df [root@localhost ~]# docker rm cd44b12ccb78e582b01ce35c8c9f7a3d920cfcfa86bff1f56fc85fc11af014df cd44b12ccb78e582b01ce35c8c9f7a3d920cfcfa86bff1f56fc85fc11af014df [root@localhost ~]# docker rmi e76a6ec6e22e Untagged: beginor/gitlab-ce:11.0.1-ce.0 Untagged: beginor/gitlab-ce@sha256:46d53b79105021f4d28c231c40fcea4a09115aa0e53da0d86c2280b68d52d14e Deleted: sha256:e76a6ec6e22ee8ac28dc7e6b46904826412c343d3b0a3ed845b9646223e69bc9
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
sonatype/nexus3 latest 36b0df681a47 12 days ago 582MB
这个时候已经删除了,我们再来试一下,
[root@localhost ~]# docker pull docker.io/gitlab/gitlab-ce [root@localhost ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE gitlab/gitlab-ce latest 15563c211d40 5 days ago 1.8GB sonatype/nexus3 latest 36b0df681a47 12 days ago 582MB [root@localhost ~]# docker run -d > -h gitlab > -p 2222:22 > -p 8090:80 > -p 8443:443 > -v /mnt/gitlab/etc:/etc/gitlab > -v /mnt/gitlab/log:/var/log/gitlab > -v /mnt/gitlab/data:/var/opt/gitlab > --restart always > --name gitlab > gitlab/gitlab-ce:latest 09b2f2ebd7232fb92f1b37b30042ba3cf031b0fb01f749edbd7c4fb762600ab0 [root@localhost ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 09b2f2ebd723 gitlab/gitlab-ce:latest "/assets/wrapper" About a minute ago Restarting (1) 1 second ago gitlab f264e5f1be41 sonatype/nexus3 "sh -c ${SONATYPE_DI…" 3 hours ago Up 3 hours 0.0.0.0:8081->8081/tcp nexus
还是不行
原文:https://www.cnblogs.com/reasonzzy/p/11145026.html