Notes on deploying gitlab based on docker | Ubuntu+Docker+GitLab

Before deploying gitlab on docker, after reading many tutorials, the deployment failed. It took a long time to get it done. Record it.

Docker-based deployment does not need to be too careful, the deployment steps are not complicated, and the big deal is that the container is deleted and rebuilt.

It is more convenient to deploy gitlab based on docker, but the server needs at least 4GB of memory, otherwise a 502 error may occur.

1. Pull the mirror

# 查询
docker search gitlab
# 拉取 默认latest
docker pull gitlab/gitlab-ce

2. Install the image

docker run \
 -itd  \
 -p 8848:80 \	# 容器80端口对应http克隆
 -p 8822:22 \ 	# 容器22端口对应ssh克隆 可以不配
 # 将容器/etc/gitlab目录挂载到宿主机/usr/local/gitlab-iot/etc目录下 下同
 -v /usr/local/gitlab-iot/etc:/etc/gitlab  \
 -v /usr/local/gitlab-iot/log:/var/log/gitlab \
 -v /usr/local/gitlab-iot/opt:/var/opt/gitlab \
 --restart always \		# 容器自启动
 --privileged=true \	# 让容器获取宿主机root权限
 --name gitlab-iot \	# 设置容器名称为gitlab-iot(可根据自己的需求更改,后面相应地方也需要更改)
 gitlab/gitlab-ce		# 镜像名称 可写镜像ID

Uncomment

docker run \
 -itd  \
 -p 8848:80 \
 -p 8822:22 \
 -v /usr/local/gitlab-iot/etc:/etc/gitlab  \
 -v /usr/local/gitlab-iot/log:/var/log/gitlab \
 -v /usr/local/gitlab-iot/opt:/var/opt/gitlab \
 --restart always \
 --privileged=true \
 --name gitlab-iot \
 gitlab/gitlab-ce

After the image is running, you can access:

  • This machine: http://localhost:8848/
  • LAN: http://gitlab-serv-IP:8848/

3. Configure the port

Configure the port when gitlab clones (the port configuration is selected according to your own needs)

# 进入容器
docker exec -it gitlab-iot /bin/bash

# 编辑配置文件
vim /etc/gitlab/gitlab.rb
# 添加内容
# gitlab 访问地址/域名
external_url 'http://192.168.1.109:8848'
# ssh IP
gitlab_rails['gitlab_ssh_host'] = '192.168.1.109'
# ssh clone 端口
gitlab_rails['gitlab_shell_ssh_port'] = 8822
# nginx 监听端口IP
nginx['listen_addresses'] = ['*']
# nginx 监听端口
nginx['listen_port'] = 80

Uncomment

#去掉注释
external_url "http://192.168.1.109:8848"
gitlab_rails['gitlab_ssh_host'] = '192.168.1.109'
gitlab_rails['gitlab_shell_ssh_port'] = 8822
nginx['listen_addresses'] = ['*']
nginx['listen_port'] = 80
# 重新配置
gitlab-ctl reconfigure

# 重启gitlab
gitlab-ctl restart

# 退出容器
exit

supplement

# 退出前,可以在容器中打开配置文件可以查看是否生效
vim /opt/gitlab/embedded/service/gitlab-rails/config/gitlab.yml

Restart container

docker restart <gitlab-container-id>

After the image is running, you can access:

  • This machine: http://localhost:8848/
  • LAN: http://gitlab-serv-IP:8848/

Guess you like

Origin blog.csdn.net/qq_40759015/article/details/109624408