官网:https://docs.gitlab.com/omnibus/docker/

GitHub:https://github.com/sameersbn/docker-gitlab

安装

docker run

  1. $ sudo docker run --detach \
  2. --hostname 10.100.68.163 \
  3. --publish 13800:80 --publish 13822:22 \
  4. --name gitlab_test \
  5. --restart always \
  6. gitlab/gitlab-ee:latest
  7. # 查看
  8. $ docker ps | grep gitlab_test
  9. # 开放端口
  10. $ firewall-cmd --add-port=13800/tcp --permanent
  11. # 更新防火墙规则
  12. $ firewall-cmd --reload
  13. # 持续输出日志
  14. $ docker logs -f gitlab_test

image.png

设置root密码

image.png

docker-gitlab

docker-compose.yml

wget https://raw.githubusercontent.com/sameersbn/docker-gitlab/master/docker-compose.yml

  1. version: '2.3'
  2. services:
  3. redis:
  4. restart: always
  5. image: redis:5.0.9
  6. command:
  7. - --loglevel warning
  8. volumes:
  9. - redis-data:/var/lib/redis:Z
  10. postgresql:
  11. restart: always
  12. image: sameersbn/postgresql:12-20200524
  13. volumes:
  14. - postgresql-data:/var/lib/postgresql:Z
  15. environment:
  16. - DB_USER=gitlab
  17. - DB_PASS=password
  18. - DB_NAME=gitlabhq_production
  19. - DB_EXTENSION=pg_trgm,btree_gist
  20. gitlab:
  21. restart: always
  22. image: sameersbn/gitlab:13.12.1
  23. depends_on:
  24. - redis
  25. - postgresql
  26. ports:
  27. - "13800:80"
  28. - "13822:22"
  29. volumes:
  30. - gitlab-data:/home/git/data:Z
  31. healthcheck:
  32. test: ["CMD", "/usr/local/sbin/healthcheck"]
  33. interval: 5m
  34. timeout: 10s
  35. retries: 3
  36. start_period: 5m
  37. environment:
  38. - DEBUG=false
  39. - DB_ADAPTER=postgresql
  40. - DB_HOST=postgresql
  41. - DB_PORT=5432
  42. - DB_USER=gitlab
  43. - DB_PASS=password
  44. - DB_NAME=gitlabhq_production
  45. - REDIS_HOST=redis
  46. - REDIS_PORT=6379
  47. - TZ=Asia/Kolkata
  48. - GITLAB_TIMEZONE=Kolkata
  49. - GITLAB_HTTPS=false
  50. - SSL_SELF_SIGNED=false
  51. - GITLAB_HOST=10.100.68.163
  52. - GITLAB_PORT=13800
  53. - GITLAB_SSH_PORT=13822
  54. - GITLAB_RELATIVE_URL_ROOT=
  55. - GITLAB_SECRETS_DB_KEY_BASE=long-and-random-alphanumeric-string
  56. - GITLAB_SECRETS_SECRET_KEY_BASE=long-and-random-alphanumeric-string
  57. - GITLAB_SECRETS_OTP_KEY_BASE=long-and-random-alphanumeric-string
  58. - GITLAB_ROOT_PASSWORD=123456789
  59. - GITLAB_ROOT_EMAIL=996194720@qq.com
  60. - GITLAB_NOTIFY_ON_BROKEN_BUILDS=true
  61. - GITLAB_NOTIFY_PUSHER=false
  62. - GITLAB_EMAIL=notifications@example.com
  63. - GITLAB_EMAIL_REPLY_TO=noreply@example.com
  64. - GITLAB_INCOMING_EMAIL_ADDRESS=reply@example.com
  65. # 备份
  66. - GITLAB_BACKUP_SCHEDULE=daily
  67. - GITLAB_BACKUP_TIME=01:00
  68. # 备份超时
  69. - GITLAB_BACKUP_EXPIRY=604800
  70. - SMTP_ENABLED=false
  71. - SMTP_DOMAIN=www.example.com
  72. - SMTP_HOST=smtp.gmail.com
  73. - SMTP_PORT=587
  74. - SMTP_USER=mailer@example.com
  75. - SMTP_PASS=password
  76. - SMTP_STARTTLS=true
  77. - SMTP_AUTHENTICATION=login
  78. - IMAP_ENABLED=false
  79. - IMAP_HOST=imap.gmail.com
  80. - IMAP_PORT=993
  81. - IMAP_USER=mailer@example.com
  82. - IMAP_PASS=password
  83. - IMAP_SSL=true
  84. - IMAP_STARTTLS=false
  85. - OAUTH_ENABLED=false
  86. - OAUTH_AUTO_SIGN_IN_WITH_PROVIDER=
  87. - OAUTH_ALLOW_SSO=
  88. - OAUTH_BLOCK_AUTO_CREATED_USERS=true
  89. - OAUTH_AUTO_LINK_LDAP_USER=false
  90. - OAUTH_AUTO_LINK_SAML_USER=false
  91. - OAUTH_EXTERNAL_PROVIDERS=
  92. - OAUTH_CAS3_LABEL=cas3
  93. - OAUTH_CAS3_SERVER=
  94. - OAUTH_CAS3_DISABLE_SSL_VERIFICATION=false
  95. - OAUTH_CAS3_LOGIN_URL=/cas/login
  96. - OAUTH_CAS3_VALIDATE_URL=/cas/p3/serviceValidate
  97. - OAUTH_CAS3_LOGOUT_URL=/cas/logout
  98. - OAUTH_GOOGLE_API_KEY=
  99. - OAUTH_GOOGLE_APP_SECRET=
  100. - OAUTH_GOOGLE_RESTRICT_DOMAIN=
  101. - OAUTH_FACEBOOK_API_KEY=
  102. - OAUTH_FACEBOOK_APP_SECRET=
  103. - OAUTH_TWITTER_API_KEY=
  104. - OAUTH_TWITTER_APP_SECRET=
  105. - OAUTH_GITHUB_API_KEY=
  106. - OAUTH_GITHUB_APP_SECRET=
  107. - OAUTH_GITHUB_URL=
  108. - OAUTH_GITHUB_VERIFY_SSL=
  109. - OAUTH_GITLAB_API_KEY=
  110. - OAUTH_GITLAB_APP_SECRET=
  111. - OAUTH_BITBUCKET_API_KEY=
  112. - OAUTH_BITBUCKET_APP_SECRET=
  113. - OAUTH_BITBUCKET_URL=
  114. - OAUTH_SAML_ASSERTION_CONSUMER_SERVICE_URL=
  115. - OAUTH_SAML_IDP_CERT_FINGERPRINT=
  116. - OAUTH_SAML_IDP_SSO_TARGET_URL=
  117. - OAUTH_SAML_ISSUER=
  118. - OAUTH_SAML_LABEL="Our SAML Provider"
  119. - OAUTH_SAML_NAME_IDENTIFIER_FORMAT=urn:oasis:names:tc:SAML:2.0:nameid-format:transient
  120. - OAUTH_SAML_GROUPS_ATTRIBUTE=
  121. - OAUTH_SAML_EXTERNAL_GROUPS=
  122. - OAUTH_SAML_ATTRIBUTE_STATEMENTS_EMAIL=
  123. - OAUTH_SAML_ATTRIBUTE_STATEMENTS_NAME=
  124. - OAUTH_SAML_ATTRIBUTE_STATEMENTS_USERNAME=
  125. - OAUTH_SAML_ATTRIBUTE_STATEMENTS_FIRST_NAME=
  126. - OAUTH_SAML_ATTRIBUTE_STATEMENTS_LAST_NAME=
  127. - OAUTH_CROWD_SERVER_URL=
  128. - OAUTH_CROWD_APP_NAME=
  129. - OAUTH_CROWD_APP_PASSWORD=
  130. - OAUTH_AUTH0_CLIENT_ID=
  131. - OAUTH_AUTH0_CLIENT_SECRET=
  132. - OAUTH_AUTH0_DOMAIN=
  133. - OAUTH_AUTH0_SCOPE=
  134. - OAUTH_AZURE_API_KEY=
  135. - OAUTH_AZURE_API_SECRET=
  136. - OAUTH_AZURE_TENANT_ID=
  137. volumes:
  138. redis-data:
  139. postgresql-data:
  140. gitlab-data:

启动

  1. $ vi docker-compose.yml
  2. $ docker-compose up -d
  3. $ docker ps
  4. $ docker logs -f di-got_gitlab_1

image.png
image.png
image.png

设置GITLAB_BACKUP_EXPIRY

自动备份

  1. $ vi ./docker-compose.yml
  2. # ...
  3. - GITLAB_BACKUP_SCHEDULE=daily
  4. - GITLAB_BACKUP_TIME=01:00
  5. - GITLAB_BACKUP_EXPIRY=604800
  6. #...
  7. # 更新配置
  8. $ docker-compose up -d

image.png

手动备份

  1. $ docker-compose run --rm gitlab app:rake gitlab:backup:create

image.png
image.png

Warning解释: 敏感信息也已经备份成功

恢复

  1. # 恢复可用的备份
  2. $ docker-compose run --rm gitlab app:rake gitlab:backup:restore
  3. # 指定恢复备份
  4. $ docker-compose run --rm gitlab app:rake gitlab:backup:restore BACKUP=1515629493_2020_12_06_13.10.0

image.png
恢复文件需要使用恢复文件的全称(包括 .tar 结尾)
image.png