gitlab需要redis,一起安装了
新建gitlab和redis挂载目录
bash
mkdir -p /data/docker/redis/data
mkdir -p /data/docker/redis/logs
mkdir -p /data/docker/redis/conf
mkdir -p /data/docker/gitlab/data
mkdir -p /data/docker/gitlab/logs
mkdir -p /data/docker/gitlab/config
给权限
bash
chmod -R 777 /data/docker/redis
chmod -R 777 /data/docker/gitlab
到/data/docker/gitlab目录下新建docker-compose.yml 文件
bash
vi docker-compose.yml
bash
version: '3'
services:
redis:
container_name: redis
image: redis
restart: always
environment:
REDIS_PASSWORD: "password"
ports:
- 6379:6379
volumes:
- /data/docker/redis/conf:/etc/redis
- /data/docker/redis/data:/data
- /data/docker/redis/logs:/logs
command: ["redis-server","/etc/redis/redis.conf"]
networks:
gitlab_network:
aliases:
- redis
depends_on:
- redis_config
redis_config:
container_name: redis_config
image: redis
command: ["sh", "-c", "echo 'requirepass password' > /etc/redis/redis.conf"]
volumes:
- /data/docker/redis/conf:/etc/redis
networks:
gitlab_network:
gitlab:
container_name: gitlab
image: 'gitlab/gitlab-ce:15.11.2-ce.0'
restart: always
depends_on:
- redis
environment:
GITLAB_OMNIBUS_CONFIG: |
external_url= "https://xxx.com"
redis_host= "redis"
redis_port= "6379"
redis_password= "password"
ports:
- "8343:443"
- "8380:80"
- "8322:22"
volumes:
- /data/docker/gitlab/config:/etc/gitlab
- /data/docker/gitlab/data:/var/opt/gitlab
- /data/docker/gitlab/logs:/var/log/gitlab
networks:
gitlab_network:
networks:
gitlab_network:
driver: bridge
/data/docker/redis/conf目录新建redis.conf空配置
bash
touch redis.conf
启动容器
bash
docker-compose up -d
修改gitlab root密码
docker exec -it gitlab bash 进入docker
输入
bash
gitlab-rails console production
换行,再输入
bash
user = User.find_by(username: 'root')
user.password = 'password'
user.password_confirmation = 'password'
user.save!
exit
重启容器
bash
docker-compose restart
-------------------------------------------------------分割线----------------------------------------------------------
如果想要gitlba支持https
进入gitlab容器
bash
docker exec -it gitlab bash
修改gitlab.rb文件
vim /etc/gitlab/gitlab.rb (可能需要使用 apt update install vim 安装vim)
bash
external_url 'https://xx.com'
#/etc/gitlab/ssl/server.crt /etc/gitlab/ssl/server.key路径依据实际情况更换
nginx['ssl_certificate'] = "/etc/gitlab/ssl/server.crt"
nginx['ssl_certificate_key'] = "/etc/gitlab/ssl/server.key"
# 下面为http跳转https配置,不需要可以不加
nginx['redirect_http_to_https'] = true
nginx['redirect_http_to_https_port'] = 80
nginx['listen_port'] = 443 #docker部署,容器内端口
容器内继续输入
bash
gitlab-ctl reconfigure
exit;退出容器,重启
bash
docker-compose restart