在Ubuntu上通过Docker容器化部署GitLab是一个相对简单且高效的方法。以下是详细的步骤指南:
准备工作
-
安装Docker:
对于基于Debian的系统(如Ubuntu),使用以下命令:sudo apt-get update sudo apt-get install -y curl openssh-server ca-certificates tzdata curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.deb.sh | sudo bash sudo apt-get install gitlab-ce -
安装Docker Compose(可选但推荐):
curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose chmod +x /usr/local/bin/docker-compose
部署步骤
-
创建
docker-compose.yml文件:
在你的主机上创建一个名为docker-compose.yml的文件,内容如下:version: '3.6' services: gitlab: image: gitlab/gitlab-ee:latest container_name: gitlab restart: always ports: - '5480:80' # GitLab web interface - '5443:443' # GitLab HTTPS - '5022:22' # SSH volumes: - './config:/etc/gitlab' - './logs:/var/log/gitlab' - './data:/var/opt/gitlab' shm_size: '256m' -
启动GitLab容器:
在包含docker-compose.yml文件的目录中运行以下命令来启动GitLab容器:docker-compose up -d -
访问GitLab:
启动容器后,你可以通过浏览器访问http://来访问GitLab的Web界面,并使用默认的root账户登录。:5480
配置GitLab
- 修改配置文件:
进入容器并修改配置文件:docker exec -it gitlab /bin/bash编辑
/etc/gitlab/gitlab.rb文件,设置外部URL和其他必要的配置项,然后重载配置:gitlab-ctl reconfigure gitlab-ctl restart
注意事项
- 防火墙设置:确保你的防火墙允许访问GitLab的默认端口(80和443)。
- 数据持久化:使用Docker卷来挂载配置、日志和数据目录,以确保在容器重启后数据不会丢失。
- 网络配置:如果你在本地环境中部署,可以使用
localhost或127.0.0.1作为服务器地址。
通过以上步骤,你应该能够在Ubuntu上成功部署GitLab。如果在部署过程中遇到问题,可以参考GitLab的官方文档或相关社区资源。