GitLab代码仓库


2022年4月17日 11:12     admin

官网

  1. https://docs.gitlab.cn/jh/install/docker.html

安装

先决条件

  1. Docker 是必需的。查看官方安装文档。

设置卷位置

  1. 在设置其他所有内容之前,请配置一个新的环境变量 $GITLAB_HOME,指向配置、日志和数据文件所在的目录。 确保该目录存在并且已授予适当的权限。
  2. 对于 Linux 用户,将路径设置为 /opt/gitlab
  3. mkdir -p /opt/gitlab
  4. export GITLAB_HOME=/opt/gitlab

  1. GITLAB_HOME 环境变量应该附加到您的 shell 的配置文件中,以便它应用于所有未来的终端会话:
  2. echo "export GITLAB_HOME=/opt/gitlab" >> ~/.bash_profile

极狐GitLab 容器使用主机装载的卷来存储持久数据:

本地位置 容器位置 使用
$GITLAB_HOME/data /var/opt/gitlab 用于存储应用程序数据。
$GITLAB_HOME/logs /var/log/gitlab 用于存储日志。
$GITLAB_HOME/config /etc/gitlab 用于存储极狐GitLab 配置文件。

安装GitLab

极狐GitLab Docker 镜像可以通过多种方式运行:


使用 Docker Engine 安装极狐GitLab

  1. docker run --detach \
  2. --hostname gitlab.example.com \
  3. --publish 443:443 --publish 80:80 --publish 22:22 \
  4. --name gitlab \
  5. --restart always \
  6. --volume $GITLAB_HOME/config:/etc/gitlab \
  7. --volume $GITLAB_HOME/logs:/var/log/gitlab \
  8. --volume $GITLAB_HOME/data:/var/opt/gitlab \
  9. --shm-size 256m \
  10. registry.gitlab.cn/omnibus/gitlab-jh:latest

访问极狐GitLab URL,并使用用户名 root 和来自以下命令的密码登录:

  1. sudo docker exec -it gitlab grep 'Password:' /etc/gitlab/initial_root_password

注意:密码文件将在 24 小时后的第一次重新配置运行中自动删除。


使用 Docker Compose 安装极狐GitLab

创建一个 docker-compose.yml 文件

  1. vim docker-compose.yml
  2. ---
  3. version: '3'
  4. services:
  5. web:
  6. image: 'registry.gitlab.cn/omnibus/gitlab-jh:latest'
  7. restart: always
  8. hostname: '172.16.2.163'
  9. environment:
  10. GITLAB_OMNIBUS_CONFIG: |
  11. external_url 'http://172.16.2.163:20080'
  12. # Add any other gitlab.rb configuration here, each on its own line
  13. ports:
  14. - '172.16.2.163:20080:80'
  15. - '172.16.2.163:20443:443'
  16. - '172.16.2.163:20022:22'
  17. volumes:
  18. - '/opt/gitlab/config:/etc/gitlab'
  19. - '/opt/gitlab/logs:/var/log/gitlab'
  20. - '/opt/gitlab/data:/var/opt/gitlab'
  21. shm_size: '256m'

确保您在与 docker-compose.yml 相同的目录下并启动极狐GitLab:

  1. docker compose up -d

修改默认端口及url

  1. version: '3'
  2. services:
  3. web:
  4. image: 'registry.gitlab.cn/omnibus/gitlab-jh:latest'
  5. restart: always
  6. hostname: 'gitlab.example.com'
  7. environment:
  8. GITLAB_OMNIBUS_CONFIG: |
  9. external_url 'http://172.16.2.163:8929'
  10. gitlab_rails['gitlab_shell_ssh_port'] = 2224
  11. ports:
  12. - '8929:8929'
  13. - '2224:22'
  14. volumes:
  15. - '$GITLAB_HOME/config:/etc/gitlab'
  16. - '$GITLAB_HOME/logs:/var/log/gitlab'
  17. - '$GITLAB_HOME/data:/var/opt/gitlab'
  18. shm_size: '256m'

访问极狐GitLab URL,并使用用户名 root 和来自以下命令的密码登录:

  1. sudo docker exec -it gitlab grep 'Password:' /etc/gitlab/initial_root_password

注意:密码文件将在 24 小时后的第一次重新配置运行中自动删除。


在公共 IP 地址上运行极狐GitLab

您可以通过修改 —publish 标志让 Docker 使用您的 IP 地址并将所有流量转发到极狐GitLab 容器。

要在 IP 198.51.100.1 上公开极狐GitLab:

  1. docker run --detach \
  2. --hostname gitlab.example.com \
  3. --publish 198.51.100.1:443:443 \
  4. --publish 198.51.100.1:80:80 \
  5. --publish 198.51.100.1:22:22 \
  6. --name gitlab \
  7. --restart always \
  8. --volume $GITLAB_HOME/config:/etc/gitlab \
  9. --volume $GITLAB_HOME/logs:/var/log/gitlab \
  10. --volume $GITLAB_HOME/data:/var/opt/gitlab \
  11. --shm-size 256m \
  12. registry.gitlab.cn/omnibus/gitlab-jh:latest

然后,您可以通过 http://198.51.100.1/https://198.51.100.1/ 访问您的极狐GitLab 实例。


设置中文