访问地址:http://192.168.31.50:9002/users/sign_in
1.关闭防火墙
#1:防火墙是否开启,开启了可以直接关闭,如果不能关闭,就把所需的端口进行开放 systemctl status firewalld #2:开放指定端口(因为22一般被sshd服务占据,所以这里用222端口) firewall-cmd --zone=dmz --add-port=80/tcp --permanent firewall-cmd --zone=dmz --add-port=443/tcp --permanent firewall-cmd --zone=dmz --add-port=22/tcp --permanent firewall-cmd --zone=dmz --add-port=222/tcp --permanent firewall-cmd --reload #刷新 firewall-cmd --zone=dmz --list-ports
2.安装,挂载出来的目录本机一定要有否则创建失败
#1:拉取gitlab镜像 docker pull gitlab/gitlab-ce #2:生成挂载目录 mkdir -p /home/gitlab/etc/gitlab mkdir -p /home/gitlab/var/log mkdir -p /home/gitlab/var/opt #3:启动容器(用的时候调整下命令,为了便于查看,有换行符) docker run -d #后台运行,全称:detach -p 8443:443 #将容器内部端口向外映射 -p 8090:80 #将容器内80端口映射至宿主机8090端口,这是访问gitlab的端口 -p 8022:22 #将容器内22端口映射至宿主机8022端口,这是访问ssh的端口 --restart always #容器自启动 --name gitlab #设置容器名称为gitlab -v /usr/local/gitlab/etc:/etc/gitlab #将容器/etc/gitlab目录挂载到宿主机/usr/local/gitlab/etc目录下,若宿主机内此目录不存在将会自动创建 -v /usr/local/gitlab/log:/var/log/gitlab #与上面一样 -v /usr/local/gitlab/data:/var/opt/gitlab #与上面一样 --privileged=true #让容器获取宿主机root权限 twang2218/gitlab-ce-zh #镜像的名称,这里也可以写镜像ID # -d:后台运行 # -p:将容器内部端口向外映射 # --name:命名容器名称 # -v:将容器内数据文件夹或者日志、配置等文件夹挂载到宿主机指定目录
hostname:可以修改成自己的IP
sudo docker run --detach \ --hostname gitlab.example.com \ --publish 9001:443 --publish 9002:80 --publish 9003:22 \ --name gitlab \ --restart always \ --volume /srv/gitlab/config:/etc/gitlab \ --volume /srv/gitlab/logs:/var/log/gitlab \ --volume /srv/gitlab/data:/var/opt/gitlab \ gitlab/gitlab-ce:latest
3.修改root密码
# 进入容器内部 docker exec -it gitlab /bin/bash # 进入控制台 gitlab-rails console -e production # 查询id为1的用户,id为1的用户是超级管理员 user = User.where(id:1).first # 修改密码为123456 user.password='123456' # 保存 user.save! # 退出 exit;
4.修改shell端口,这个要和启动的时候端口一致
cd /srv/gitlab/config --- 这个是自己配置的挂载路径
vim gitlab.rb
674 ### Wait for file system to be mounted 675 ###! Docs: https://docs.gitlab.com/omnibus/settings/configuration.html#only-start-omnibus-gitlab-services-after-a-given-file-system-is-mounted 676 # high_availability['mountpoint'] = ["/var/opt/gitlab/git-data", "/var/opt/gitlab/gitlab-rails/shared"] 677 678 ### GitLab Shell settings for GitLab 679 gitlab_rails['gitlab_shell_ssh_port'] = 9003 680 # gitlab_rails['gitlab_shell_git_timeout'] = 800 681 682 ### Extra customization 683 # gitlab_rails['extra_google_analytics_id'] = '_your_tracking_id' 684 # gitlab_rails['extra_google_tag_manager_id'] = '_your_tracking_id' 685 # gitlab_rails['extra_one_trust_id'] = '_your_one_trust_id' 686 # gitlab_rails['extra_google_tag_manager_nonce_id'] = '_your_google_tag_manager_id' 687 # gitlab_rails['extra_bizible'] = false 688 # gitlab_rails['extra_matomo_url'] = '_your_matomo_url' 689 # gitlab_rails['extra_matomo_site_id'] = '_your_matomo_site_id' 690 # gitlab_rails['extra_matomo_disable_cookies'] = false 691 # gitlab_rails['extra_maximum_text_highlight_size_kilobytes'] = 512 692 693 ##! Docs: https://docs.gitlab.com/omnibus/settings/environment-variables.html 694 # gitlab_rails['env'] = { 695 # 'BUNDLE_GEMFILE' => "/opt/gitlab/embedded/service/gitlab-rails/Gemfile", 696 # 'PATH' => "/opt/gitlab/bin:/opt/gitlab/embedded/bin:/bin:/usr/bin" 697 # }
那个文件docker云行完之后才有,修改完要重启。