Use docker installation gitlab

Gitlab git as open source code repository, powerful, very convenient to use. This article describes how to use the docker to install gitlab.

This article assumes that good docker has been installed, you can enter docker --versionwhether to verify that the normal installation, the output:

Docker version 19.03.5, build 633a0ea

Use docker run command to install

To facilitate installation, let's pull the latest version of gitlab community Mirror version:

docker pull gitlab/gitlab-ce:latest

Then, docker runrun gitlab:

docker run --detach \
  --hostname 127.0.0.1 \
  --publish 443:443 --publish 80:80 --publish 22:22 \
  --name gitlab \
  --restart always \
  --volume /Users/lihao/code/docker/gitlab-ce/config:/etc/gitlab \
  --volume /Users/lihao/code/docker/gitlab-ce/logs:/var/log/gitlab \
  --volume /Users/lihao/code/docker/gitlab-ce/data:/var/opt/gitlab \
  gitlab/gitlab-ce:latest

docker run Command using a plurality of parameters, the effect of these parameters is as follows:

  • --detach: Background container
  • --publish: Port mapping, mapping how the container port to the host (referred to herein as our Mac computers) port
  • --name: Specifies the name of the vessel, here we specify the name of the vessel gitlab
  • --restart always: Set when the host after reboot, restart of the container will
  • --volume: Bind mount manner used here, provided gitlab data stored in the directory of the container /Users/lihao/code/docker/gitlab-ce/at

About using docker volume, you can refer to the article "Docker data persistence" .

Gitlab containers bind mount manner persistent data in the following table:

Local Directory Container directory use
/Users/lihao/code/docker/gitlab-ce/config /etc/gitlab Save Configuration gitlab
/Users/lihao/code/docker/gitlab-ce/logs /var/log/gitlab Save gitlab output log
/Users/lihao/code/docker/gitlab-ce/data /var/opt/gitlab Save gitlab application data

Implementation of the above docker runcommand, we then transferred back to the local directory /Users/lihao/code/docker/gitlab-ce/config, open the file gitlab.rband modify external_urlas http://127.0.0.1, in order to use the address http://127.0.0.1to access gitlab.

Then, execute the command to restart gitlab.

docker restart gitlab

Start gitlab container process, you can use the command to view the log output of the boot process.

docker logs -f gitlab

Open your browser and enter the address http://127.0.0.1/, update your password and use the root username, you can see gitlab have normal access.

使用 docker-compose 安装

使用 docker-compose 可以更方便配置、安装 gitlab。安装 gitlab 的 docker-compose.yml 文件如下:

version: '3'
services:
  web:
    image: 'gitlab/gitlab-ce:latest'
    restart: always
    hostname: '127.0.0.1'
    environment:
      GITLAB_OMNIBUS_CONFIG: |
        external_url 'http://127.0.0.1'
    ports:
      - '80:80'
      - '443:443'
      - '22:22'
    volumes:
      - '/Users/lihao/code/docker/gitlab-compose/config:/etc/gitlab'
      - '/Users/lihao/code/docker/gitlab-compose/logs:/var/log/gitlab'
      - '/Users/lihao/code/docker/gitlab-compose/data:/var/opt/gitlab'

可以看到,docker-compose.yml 文件的参数与上述 docker run 命令的参数相似。为了方便配置 gitlab 的 external_url 配置,我们通过直接指定环境变量 GITLAB_OMNIBUS_CONFIG 的方式实现。

另外,为了与上面安装的 gitlab 数据不冲突,我们使用了本地另一个目录来保存容器的数据。

关闭上面启动的 gitlab 容器,然后在 docker-compose.yml 文件所在目录,执行以下命令:

docker-compose up -d

等待执行一段时间以后(笔者在安装 gitlab 过程中,发现执行命令后马上访问 gitlab 会报 502 错误,等待一段时间又好了),打开浏览器,输入地址,同时可以正常访问 gitlab。

参考资料

  • https://docs.gitlab.com/omnibus/docker/
发布了191 篇原创文章 · 获赞 441 · 访问量 123万+

Guess you like

Origin blog.csdn.net/lihao21/article/details/104264224