• DevOps


    1 - GitLab镜像

    官网信息GitLab-CE:https://docs.gitlab.com/ce/install/docker.html
    镜像

    2 - 拉取镜像

    命令
    docker pull gitlab/gitlab-ce

    实例

    [root@h200 ~]# docker pull gitlab/gitlab-ce
    Using default tag: latest
    latest: Pulling from gitlab/gitlab-ce
    976a760c94fc: Pull complete 
    c58992f3c37b: Pull complete 
    0ca0e5e7f12e: Pull complete 
    f2a274cc00ca: Pull complete 
    984575bb5360: Pull complete 
    f37421c0d9f0: Pull complete 
    f5e6f94abad8: Pull complete 
    d4082c13edfd: Pull complete 
    51fbd684ae90: Pull complete 
    e01aeeec631a: Pull complete 
    Digest: sha256:07284eade0994f2b63edcdf57e8bed28b3cc95b9cd4eccab3ffaa3b190cd8171
    Status: Downloaded newer image for gitlab/gitlab-ce:latest
    docker.io/gitlab/gitlab-ce:latest
    [root@h200 ~]# 
    [root@h200 ~]# docker images
    REPOSITORY            TAG                 IMAGE ID            CREATED             SIZE
    jenkinsci/blueocean   latest              fee7a600b49c        30 hours ago        563MB
    gitlab/gitlab-ce      latest              5737e50aaa01        43 hours ago        1.82GB
    postgres              10                  1ba73c5b23e7        2 weeks ago         250MB
    sonarqube             7.9.1-community     ea9ce8f562b5        2 weeks ago         480MB
    sonarqube             7.5-community       88a9b8f332d0        10 months ago       843MB
    hello-world           latest              fce289e99eb9        11 months ago       1.84kB
    [root@h200 ~]#
    

    3 - 创建容器

    docker run -d 
    -p 4430:443 -p 800:80 -p 220:22 
    --name gitlab 
    --restart unless-stopped 
    -v /opt/gitlab/config:/etc/gitlab 
    -v /opt/gitlab/logs:/var/log/gitlab 
    -v /opt/gitlab/data:/var/opt/gitlab 
    -v /etc/localtime:/etc/localtime 
    gitlab/gitlab-ce
    
    

    参数解释

    • -d:后台运行
    • -p:容器内部端口向外映射
    • --name:命名容器名称
    • --restart:重启策略
    • -v:将容器GitLab 的配置、 日志 、数据等文件夹挂载到宿主机指定目录,便于日后升级
    • -v /etc/localtime:/etc/localtime :将容器时间和host设为同一个时区

    实例

    [root@h200 ~]# docker run -d -p 4430:443 -p 800:80 -p 220:22 --name gitlab --restart unless-stopped -v /opt/gitlab/config:/etc/gitlab -v /opt/gitlab/logs:/var/log/gitlab -v /opt/gitlab/data:/var/opt/gitlab -v /etc/localtime:/etc/localtime gitlab/gitlab-ce
    118c5fc2cc0abef3207dacae52d043c3897228943649d5b8342fe3abf51b2ef2
    [root@h200 ~]# 
    [root@h200 ~]# docker ps
    CONTAINER ID        IMAGE                 COMMAND                  CREATED             STATUS                            PORTS                                                             NAMES
    118c5fc2cc0a        gitlab/gitlab-ce      "/assets/wrapper"        11 seconds ago      Up 9 seconds (health: starting)   0.0.0.0:220->22/tcp, 0.0.0.0:800->80/tcp, 0.0.0.0:4430->443/tcp   gitlab                                                                        loving_nash
    [root@h200 ~]# 
    [root@h200 ~]# date
    Thu Dec 19 17:45:17 CST 2019
    [root@h200 ~]# 
    [root@h200 ~]# docker exec -i gitlab date
    Thu Dec 19 17:45:16 CST 2019
    [root@h200 ~]#
    
    

    4 - 开通防火墙端口

    [root@h200 ~]# firewall-cmd --zone=public --permanent --add-port=800/tcp
    success
    [root@h200 ~]# firewall-cmd --zone=public --permanent --add-port=4430/tcp
    success
    [root@h200 ~]# firewall-cmd --zone=public --permanent --add-port=220/tcp
    success
    [root@h200 ~]# 
    [root@h200 ~]# firewall-cmd --reload
    success
    [root@h200 ~]#
    
    

    5 - 配置GitLab主机名

    以容器方式运行gitlab,在gitlab上创建项目时,生成项目的URL访问地址是按容器ID来生成的,
    需要配置gitlab.rb文件(GitLab的/etc/gitlab目录)来指定一个更加明确的固定URL访问地址。

    添加如下内容并重启GitLab容器

    external_url 'http://192.168.16.200:800'
    gitlab_rails['gitlab_ssh_host'] = '192.168.16.200'
    gitlab_rails['gitlab_shell_ssh_port'] = 220
    

    实例

    [root@h200 ~]# vim /opt/gitlab/config/gitlab.rb 
    [root@h200 ~]# 
    [root@h200 ~]# cat /opt/gitlab/config/gitlab.rb |grep -v "#" |grep -Ev "^$"
    external_url 'http://192.168.16.200'
    gitlab_rails['gitlab_ssh_host'] = '192.168.16.200'
    gitlab_rails['gitlab_shell_ssh_port'] = 220
    [root@h200 ~]# 
    [root@h200 ~]# docker restart gitlab
    gitlab
    [root@h200 ~]# 
    [root@h200 ~]# docker ps
    CONTAINER ID        IMAGE                 COMMAND                  CREATED             STATUS                             PORTS                                                             NAMES
    118c5fc2cc0a        gitlab/gitlab-ce      "/assets/wrapper"        26 minutes ago      Up 14 seconds (health: starting)   0.0.0.0:220->22/tcp, 0.0.0.0:800->80/tcp, 0.0.0.0:4430->443/tcp   gitlab                                                                             loving_nash
    [root@h200 ~]# 
    [root@h200 ~]# docker ps 
    CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                    PORTS                                                             NAMES
    118c5fc2cc0a        gitlab/gitlab-ce    "/assets/wrapper"   44 minutes ago      Up 17 minutes (healthy)   0.0.0.0:220->22/tcp, 0.0.0.0:800->80/tcp, 0.0.0.0:4430->443/tcp   gitlab
    [root@h200 ~]#
    
    

    确认project信息是否已更改

    6 -  数据留存

    通过-v参数挂载的主机文件在容器停止或删除后,仍然存在,可以在之后创建gitlab容器时,再次挂载。

    [root@h200 ~]# docker ps
    CONTAINER ID        IMAGE                 COMMAND                  CREATED             STATUS                      PORTS                                                             NAMES
    118c5fc2cc0a        gitlab/gitlab-ce      "/assets/wrapper"        47 minutes ago      Up 20 minutes (healthy)     0.0.0.0:220->22/tcp, 0.0.0.0:800->80/tcp, 0.0.0.0:4430->443/tcp   gitlab                                                                    loving_nash
    [root@h200 ~]# docker stop gitlab
    gitlab
    [root@h200 ~]# docker rm gitlab
    gitlab
    [root@h200 ~]# docker ps
    CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
    [root@h200 ~]# docker ps -a
    CONTAINER ID        IMAGE                 COMMAND                  CREATED             STATUS                      PORTS               NAMES
    b69079fb1adb        jenkinsci/blueocean   "/sbin/tini -- /usr/…"   42 hours ago        Exited (143) 41 hours ago                       myjenkins
    9278594040d7        hello-world           "/hello"                 43 hours ago        Exited (0) 43 hours ago                         loving_nash
    [root@h200 ~]# ll /opt/gitlab/
    total 4
    drwxrwxr-x  3 root root  239 Dec 19 17:11 config
    drwxr-xr-x 20 root root 4096 Dec 19 17:11 data
    drwxr-xr-x 20 root root  329 Dec 19 16:48 logs
    [root@h200 ~]#
    
    
  • 相关阅读:
    4-6 随机数
    linux下安装jdk
    markdown使用教程
    IDE新建gradle各种坑
    day05泛型类和泛型方法
    day05集合
    day15 Ui自动化中三种等待方式
    day15 Ui自动化元素的定位
    Windows系统
    解决sublime text 3使用Install Package时出现There are no packages available for installation问题
  • 原文地址:https://www.cnblogs.com/anliven/p/12070966.html
Copyright © 2020-2023  润新知