docker安装gitlab

1.启动postgresql数据库容器

 

[plain] view plain copy
  1. docker run --name gitlab-postgresql -d \  
  2.     --env 'DB_NAME=gitlabhq_production' \  
  3.     --env 'DB_USER=gitlab' --env 'DB_PASS=password' \  
  4.     --env 'DB_EXTENSION=pg_trgm' \  
  5.     --volume /srv/docker/gitlab/postgresql:/var/lib/postgresql \  
  6.     sameersbn/postgresql:9.5-3  



 


2.启动redis消息容器

[html] view plain copy
  1. docker run --name gitlab-redis -d \  
  2.     --volume /srv/docker/gitlab/redis:/var/lib/redis \  
  3.     sameersbn/redis:latest  


3.启动gitlab容器

[html] view plain copy
  1. docker run --name gitlab -d \  
  2.     --link gitlab-postgresql:postgresql --link gitlab-redis:redisio \  
  3.     --publish 10022:22 --publish 10080:80 \  
  4.     --env 'GITLAB_PORT=10080' --env 'GITLAB_SSH_PORT=10022' \  
  5.     --env 'GITLAB_SECRETS_DB_KEY_BASE=long-and-random-alpha-numeric-string' \  
  6.     --env 'GITLAB_SECRETS_SECRET_KEY_BASE=long-and-random-alpha-numeric-string' \  
  7.     --env 'GITLAB_SECRETS_OTP_KEY_BASE=long-and-random-alpha-numeric-string' \  
  8.     --volume /srv/docker/gitlab/gitlab:/home/git/data \  
  9.     sameersbn/gitlab:8.14.0  


由于dockerhub的镜像非常慢,我们这里改一下使用灵雀云的镜像(就是改了一下镜像名和版本),虽然版本可能会跟不上最新的,但是速度快多了(实际上也不怎么快,我用了两个小时下载。。。)

[html] view plain copy
  1. docker run --name gitlab-postgresql -d \  
  2.     --env 'DB_NAME=gitlabhq_production' \  
  3.     --env 'DB_USER=gitlab' --env 'DB_PASS=password' \  
  4.     --env 'DB_EXTENSION=pg_trgm' \  
  5.     --volume /srv/docker/gitlab/postgresql:/var/lib/postgresql \  
  6.     index.alauda.cn/sameersbn/postgresql  
  7.   
  8. docker run --name gitlab-redis -d \  
  9.     --volume /srv/docker/gitlab/redis:/var/lib/redis \  
  10.     index.alauda.cn/sameersbn/redis:latest  
  11.   
  12. docker run --name gitlab -d \  
  13.     --link gitlab-postgresql:postgresql --link gitlab-redis:redisio \  
  14.     --publish 10022:22 --publish 10080:80 \  
  15.     --env 'GITLAB_PORT=10080' --env 'GITLAB_SSH_PORT=10022' \  
  16.     --env 'GITLAB_SECRETS_DB_KEY_BASE=long-and-random-alpha-numeric-string' \  
  17.     --env 'GITLAB_SECRETS_SECRET_KEY_BASE=long-and-random-alpha-numeric-string' \  
  18.     --env 'GITLAB_SECRETS_OTP_KEY_BASE=long-and-random-alpha-numeric-string' \  
  19.     --volume /srv/docker/gitlab/gitlab:/home/git/data \  
  20.     index.alauda.cn/sameersbn/gitlab:latest  

 

阿里云上也有这个镜像,不过有些地址是废弃的,需要试一下

 

[plain] view plain copy
  1. docker run --name gitlab-postgresql -d \  
  2.     --env 'DB_NAME=gitlabhq_production' \  
  3.     --env 'DB_USER=gitlab' --env 'DB_PASS=password' \  
  4.     --env 'DB_EXTENSION=pg_trgm' \  
  5.     --volume /srv/docker/gitlab/postgresql:/var/lib/postgresql \  
  6.     registry.cn-hangzhou.aliyuncs.com/acs-sample/postgresql-sameersbn    
  7.   
  8. #docker pull registry.cn-hangzhou.aliyuncs.com/acs-sample/sameersbn-postgresql #这个地址已经废弃但还是可以搜索到  
  9.   
  10. docker run --name gitlab-redis -d \  
  11.     --volume /srv/docker/gitlab/redis:/var/lib/redis \  
  12.     registry.cn-hangzhou.aliyuncs.com/acs-sample/sameersbn-redis:latest  
  13.   
  14. docker run --name gitlab -d \  
  15.     --link gitlab-postgresql:postgresql --link gitlab-redis:redisio \  
  16.     --publish 10022:22 --publish 10080:80 \  
  17.     --env 'GITLAB_PORT=10080' --env 'GITLAB_SSH_PORT=10022' \  
  18.     --env 'GITLAB_SECRETS_DB_KEY_BASE=long-and-random-alpha-numeric-string' \  
  19.     --env 'GITLAB_SECRETS_SECRET_KEY_BASE=long-and-random-alpha-numeric-string' \  
  20.     --env 'GITLAB_SECRETS_OTP_KEY_BASE=long-and-random-alpha-numeric-string' \  
  21.     --volume /srv/docker/gitlab/gitlab:/home/git/data \  
  22.     registry.cn-hangzhou.aliyuncs.com/acs-sample/gitlab-sameersbn:latest  
  23.   
  24. #docker pull registry.cn-hangzhou.aliyuncs.com/acs-sample/sameersbn-gitlab #这个地址已经废弃但还是可以搜索到  



 

浏览器访问http://localhost:10080设置root密码,密码不能少于8个字符,最开始可能会出现502的界面,刷新几次就好了。

 

放几张安装成功到截图

 

灵雀云上最新的版本是8.8.5,阿里云上最新的版本是810.3,github上最新的是8.14.0

 

如果重启了电脑,你可以通过下面的方式重启gitlab

[html] view plain copy
  1. docker restart gitlab-postgresql  
  2. docker restart gitlab-redis  
  3. docker restart gitlab  



重启并没有丢失数据,因为--volume挂载卷命令将数据保存到了本地

常用命令

[html] view plain copy
  1. docker ps #查看容器  
  2. docker ps -a #查看所有容器,包括已经停止的。  
  3. docker ps -l #查看正在运行的容器  
  4. docker rm [容器名或容器ID] #删除单个容器  
  5. #停止、启动、杀死、重启一个容器  
  6. docker stop [容器名或容器ID]  
  7. docker start [容器名或容器ID]  
  8. docker kill [容器名或容器ID]  
  9. docker restart [容器名或容器ID]  

 

域名问题

在启动gitlab时可以通过环境变量GITLAB_HOST指定

 

[html] view plain copy
    1. --env 'GITLAB_HOST=gitlab.example.com' \  
posted @ 2018-06-25 22:19  GᎭ•Cristin  阅读(265)  评论(0编辑  收藏  举报