├── gitlab-install.md └── images ├── addssh.png ├── create.png ├── file.png ├── gitindex.png ├── register.png ├── rootpass.png └── sshkey.png /gitlab-install.md: -------------------------------------------------------------------------------- 1 | # GitLab安装、使用教程(Docker版) 2 | ## 一、下载镜像 3 | 官方版本是:gitlab/gitlab-ce:latest,为了提升速度我们这里使用阿里云的仓库 4 | ```bash 5 | $ docker pull registry.cn-hangzhou.aliyuncs.com/imooc/gitlab-ce:latest 6 | ``` 7 | 8 | ## 二、运行GitLab容器 9 | 使用docker命令运行容器,注意修改hostname为自己喜欢的名字,-v部分挂载目录要修改为自己的目录。 10 | 端口映射这里使用的都是安全端口,如果大家的环境没有端口限制或冲突可以使用与容器同端口,如:-p 443:443 -p 80:80 -p 22:22 11 | #### 1. 生成启动文件 - start.sh 12 | ```bash 13 | $ cat < start.sh 14 | #!/bin/bash 15 | HOST_NAME=gitlab.mooc.com 16 | GITLAB_DIR=`pwd` 17 | docker stop gitlab 18 | docker rm gitlab 19 | docker run -d \\ 20 | --hostname \${HOST_NAME} \\ 21 | -p 8443:443 -p 8080:80 -p 2222:22 \\ 22 | --name gitlab \\ 23 | -v \${GITLAB_DIR}/config:/etc/gitlab \\ 24 | -v \${GITLAB_DIR}/logs:/var/log/gitlab \\ 25 | -v \${GITLAB_DIR}/data:/var/opt/gitlab \\ 26 | registry.cn-hangzhou.aliyuncs.com/imooc/gitlab-ce:latest 27 | EOF 28 | ``` 29 | #### 2. 运行start.sh 启动gitlab 30 | ```bash 31 | $ sh start.sh 32 | ``` 33 | 34 | #### 3. 配置环境 35 | * 修改host文件,使域名可以正常解析 36 | > 127.0.0.1 gitlab.mooc.com 37 | 38 | * 修改ssh端口(如果主机端口使用的不是22端口) 39 | > 修改文件:${GITLAB_DIR}/config/gitlab.rb 40 | > 找到这一行:# gitlab_rails['gitlab_shell_ssh_port'] = 22 41 | > 把22修改为你的宿主机端口(这里是2222)。然后将注释去掉。 42 | 43 | * 重新启动容器 44 | ```bash 45 | $ sh start.sh 46 | ``` 47 | 48 | ## 三、GitLab试用 49 | #### 1. 打开首页 50 | 地址:http://gitlab.mooc.com:8080/ 51 | 52 | #### 2. 设置管理员密码 53 | 首先根据提示输入管理员密码,这个密码是管理员用户的密码。对应的用户名是root,用于以管理员身份登录Gitlab。 54 | 55 | 56 | #### 3. 创建账号 57 | 设置好密码后去注册一个普通账号 58 | 59 | 60 | #### 4. 创建项目 61 | 注册成功后会跳到首页,我们创建一个项目,名字大家随意 62 | 63 | 64 | #### 5. 添加ssh key 65 | 项目建好了,我们加一个ssh key,以后本地pull/push就简单啦 66 | 67 | 68 | 首先去到添加ssh key的页面 69 | 70 | 71 | 然后拿到我们的sshkey 贴到框框里就行啦 72 | 怎么拿到呢?看下面: 73 | ```bash 74 | #先看看是不是已经有啦,如果有内容就直接copy贴过去就行啦 75 | $ cat ~/.ssh/id_rsa.pub 76 | 77 | #如果上一步没有这个文件 我们就创建一个,运行下面命令(邮箱改成自己的哦),一路回车就好了 78 | $ ssh-keygen -t rsa -C "youremail@example.com" 79 | $ cat ~/.ssh/id_rsa.pub 80 | ``` 81 | 82 | #### 6. 测试一下 83 | 点开我们刚创建的项目,复制ssh的地址 84 | 85 | 86 | 添加个文件试试(我的项目叫test) 87 | ```bash 88 | #clone代码 89 | $ git clone ssh://git@gitlab.mooc.com:2222/michael/test.git 90 | #写一个文件 91 | $ cd test && echo test > test 92 | #push 93 | $ git add . 94 | $ git commit -m "test" 95 | $ git push origin master 96 | ``` 97 | 98 | 去gitlab上看看 99 | 100 | 101 | 到这我们的gitlab就齐活啦!愉快的使用吧~ 102 | 103 | -------------------------------------------------------------------------------- /images/addssh.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liuyi01/imooc-docs/81826fa09d6ed55a6f521d6a878f59c6f6d6639c/images/addssh.png -------------------------------------------------------------------------------- /images/create.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liuyi01/imooc-docs/81826fa09d6ed55a6f521d6a878f59c6f6d6639c/images/create.png -------------------------------------------------------------------------------- /images/file.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liuyi01/imooc-docs/81826fa09d6ed55a6f521d6a878f59c6f6d6639c/images/file.png -------------------------------------------------------------------------------- /images/gitindex.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liuyi01/imooc-docs/81826fa09d6ed55a6f521d6a878f59c6f6d6639c/images/gitindex.png -------------------------------------------------------------------------------- /images/register.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liuyi01/imooc-docs/81826fa09d6ed55a6f521d6a878f59c6f6d6639c/images/register.png -------------------------------------------------------------------------------- /images/rootpass.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liuyi01/imooc-docs/81826fa09d6ed55a6f521d6a878f59c6f6d6639c/images/rootpass.png -------------------------------------------------------------------------------- /images/sshkey.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liuyi01/imooc-docs/81826fa09d6ed55a6f521d6a878f59c6f6d6639c/images/sshkey.png --------------------------------------------------------------------------------