由於我打算使用公用的redis,因此先建立一個redis鏡像mysql
首先建立一個docker目錄(如下以G盤爲例)git
在docker目錄下建立redis目錄web
在redis目錄下添加文件docker-compose.yml文件,內容爲:redis
(2018年4月11日修改volumes下面的掛載volume不使用/g/docker/redis/xxx方式,在最新版docker中已不能使用,改成docker-compose.yml的相對路徑./redis/conf來掛載)sql
version: '3'
services:
redis:
image: redis:4.0.8-alpine
container_name: db-redis
restart: always
ports:
- 6379:6379
networks:
- net_db
volumes:
- ./redis/config:/docker/config
- ./redis/data:/data
command: redis-server /docker/config/redis.conf
networks:
net_db:
external: true
在redis目錄下添加config目錄chrome
在config目錄下添加redis.conf文件,內容爲:docker
#redis的databases數量
databases 32
#redis密碼
requirepass 123
回到redis目錄,打開vscode、powershell或者cmdshell
首先建立一個network,而後執行docker-compose -d upubuntu
PS G:\docker\redis> docker network create net_db
0583088e9269e9d1e7029682f409690547ae9325b0aee795b3d76676b7409abc
PS G:\docker\redis> docker-compose up -d
Creating db-redis ... done
PS G:\docker\redis> docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b0b552dc45fa redis:4.0.8-alpine "docker-entrypoint.s…" 38 seconds ago Up 35 seconds 0.0.0.0:6379->6379/tcp db-redis
啓動成功,用客戶端鏈接測試localhost:6379@123(密碼)鏈接正常windows
接下來開始啓動Gitlab
在docker目錄下建立gitlab目錄
在其中建立docker-compose.yml文件,內容爲:
version: '3'
services:
gitlab:
image: 'twang2218/gitlab-ce-zh:10.4.3'
container_name: gitlab-1043
restart: unless-stopped
environment:
TZ: 'Asia/Shanghai'
GITLAB_OMNIBUS_CONFIG: |
external_url 'http://gitlab-1043'
gitlab_rails['time_zone'] = 'Asia/Shanghai'
#如下爲啓用郵件相關設置,我用的是阿里雲免費企業郵箱
gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = 'smtp.mxhichina.com'
gitlab_rails['smtp_port'] = 465
gitlab_rails['smtp_user_name'] = '個人阿里雲企業郵箱帳號'
gitlab_rails['smtp_password'] = '個人阿里雲企業郵箱密碼'
gitlab_rails['smtp_domain'] = '個人阿里雲企業郵箱域名'
gitlab_rails['smtp_authentication'] = 'plain'
gitlab_rails['smtp_enable_starttls_auto'] = true
gitlab_rails['smtp_tls'] = true
gitlab_rails['gitlab_email_from'] = '收到郵件時顯示的發送郵箱'
user["git_user_email"] = '用戶郵箱地址,跟上一條同樣'
#修改sidekiq的數量,減小內存佔用,默認爲15,也能夠不填
sidekiq['concurrency'] = 10
#使用外部redis所需設置,根據剛剛生成的redis設置修改
gitlab_rails['redis_port'] = 6379
gitlab_rails['redis_host'] = 'db-redis'
gitlab_rails['redis_password'] = '123'
gitlab_rails['redis_database'] = '1'
#由於22端口被佔用,修改映射的端口號時,同時修改在Gitlab項目中的ssh地址加上端口號
gitlab_rails['gitlab_shell_ssh_port'] = 10022
ports:
- '10080:80'
- '10443:443'
- '10022:22'
networks:
- net_db
volumes:
- ./config:/etc/gitlab
- gitlab-data:/var/opt/gitlab
- ./logs:/var/log/gitlab
volumes:
gitlab-data:
external: true
networks:
net_db:
external: true
在Docker內部建立一個volume,而後執行docker-compose -d up
PS G:\docker\gitlab> docker volume create gitlab-data
gitlab-data
PS G:\docker\gitlab> docker-compose up -d
Creating gitlab-1043 ... done
PS G:\docker\gitlab> docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS
NAMES
c7cba6a06740 twang2218/gitlab-ce-zh:10.4.3 "/assets/wrapper" 29 seconds ago Up 24 seconds (health: starting) 0.0.0.0:10022->22/tcp, 0.0.0.0:10080->80/tcp, 0.0.0.0:10443->443/tcp gitlab-1043
b0b552dc45fa redis:4.0.8-alpine "docker-entrypoint.s…" 14 minutes ago Up 14 minutes 0.0.0.0:6379->6379/tcp
db-redis
等待Gitlab本身生成配置完成之後,就能夠訪問http://localhost:10080訪問gitlab了
能夠在等待時輸入docker logs -f gitlab-1043跟蹤gitlab的生成狀態

若是須要備份出來gitlab-data的數據,能夠建立一個臨時的鏡像方式把文件copy出來
PS G:\docker> docker run --name data -v /g/docker/backup:/backup -v gitlab-data:/data ubuntu:17.10 cp -r /data/ /backup/
cp: cannot create special file '/backup/data/postgresql/.s.PGSQL.5432': Operation not permitted
cp: cannot create special file '/backup/data/redis/redis.socket': Operation not permitted
cp: cannot create special file '/backup/data/gitlab-rails/sockets/gitlab.socket': Operation not permitted
cp: cannot create special file '/backup/data/gitlab-workhorse/socket': Operation not permitted
cp: cannot create special file '/backup/data/gitaly/gitaly.socket': Operation not permitted
PS G:\docker> docker rm data
data
上面這幾個沒法copy的文件就是致使不能使用volume直接掛載在windows目錄下的緣由,其餘文件均可以正常備份和修改