制作docker gitlab容器步骤
创建Dockerfile文件
1
2mkdir gitlab-docker && cd gitlab-docker
touch Dockerfile编写Dockerfile内容
1
2
3
4
5
6
7
8
9
10
11
12# 使用GitLab官方镜像作为基础
FROM gitlab/gitlab-ce:16.10.2-ce.0
# 设置时区(可选)
ENV TZ=Asia/Shanghai
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
# 持久化数据目录声明(推荐在运行时挂载)
VOLUME ["/etc/gitlab", "/var/log/gitlab", "/var/opt/gitlab"]
# 暴露常用端口
EXPOSE 80 443 22构建Docker镜像
1
docker build -t my-gitlab:16.10.2 .
运行Gitlab容器
1
2
3
4
5
6
7
8
9
10
11
12docker run -d \
--name gitlab \
--hostname gitlab.example.com \
--publish 8080:80 \
--publish 8443:443 \
--publish 2222:22 \
--volume $PWD/gitlab/config:/etc/gitlab \
--volume $PWD/gitlab/logs:/var/log/gitlab \
--volume $PWD/gitlab/data:/var/opt/gitlab \
--shm-size 256m \
--restart always \
my-gitlab:16.10.2gitlab.example.com
修改为接口IP- 端口映射:将容器端口
80/443/22
映射到主机的8080/8443/2222
- 数据卷挂载:将 宿主机的数据卷:容器数据卷 进行挂载
config
: GitLab 配置文件logs
: 日志文件data
: 应用数据(仓库、数据库等)
--shm-size
: 解决Sidekiq内存不足问题--hostname
: 设置GitLab实例的访问域名
首次访问设置(设置root用户密码)
1
2
3
4
5
6
7
8
9docker exec -it gitlab /bin/bash
gitlab-rails console
irb(main):001:0> u=User.where(id:1).first
=> #<User id:1 @root>
irb(main):002:0> u.password='xxxxx'
=> "xxxxx"
irb(main):003:0> u.save!
=> true
irb(main):004:0> exit