安装docker
# 安装yum-config-manager配置工具
yum -y install yum-utils
# 设置yum源
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
# 安装docker-ce版本
yum install -y docker-ce
# 启动并设置开机自启
systemctl start docker && systemctl enable docker
# 查看版本号
docker -v
# 查看版本具体信息
docker version
# Docker镜像源设置
# 修改文件 /etc/docker/daemon.json,没有这个文件就创建
# 添加以下内容后,重启docker服务:
cat >/etc/docker/daemon.json<<EOF
{
"registry-mirrors": [
"http://hub-mirror.c.163.com",
"https://7vnz06qj.mirror.aliyuncs.com"
],
"exec-opts": ["native.cgroupdriver=systemd"]
}
EOF
# 加载
systemctl reload docker && systemctl restart docker
安装gitlab
官方docker仓库:https://hub.docker.com/r/gitlab/gitlab-ce/tags
docker pull gitlab/gitlab-ce:13.12.3-ce.0
docker pull gitlab/gitlab-ce:latest
# 创建目录声,明挂载目录
cd && mkdir gitlab && cd gitlab && export GITLAB_HOME=/root/gitlab
# 运行最新版本gitlab
docker run -d \
--name gitlab \
-p 443:443 -p 80:80 -p 222:22 \
--restart always \
-v $GITLAB_HOME/config:/etc/gitlab \
-v $GITLAB_HOME/logs:/var/log/gitlab \
-v $GITLAB_HOME/data:/var/opt/gitlab \
gitlab/gitlab-ce:latest
# 运行指定版本gitlab
docker run -d \
--name gitlab \
-p 443:443 -p 80:80 -p 222:22 \
--restart always \
-v $GITLAB_HOME/config:/etc/gitlab \
-v $GITLAB_HOME/logs:/var/log/gitlab \
-v $GITLAB_HOME/data:/var/opt/gitlab \
gitlab/gitlab-ce:13.12.3-ce.0
docker ps
docker ps -a
docker logs -f gitlab
访问地址:http://192.168.25.4
超级重要:
# 修改/root/gitlab/config/gitlab.rb文件
external_url 'http://192.168.25.4'
gitlab_rails['gitlab_shell_ssh_port'] = 222
# 重启gitlab容器
docker restart gitlab
GitLab 配置 SSH 密钥
ssh-keygen -t rsa -C "gao15540451242@163.com"
cat ~/.ssh/id_rsa.pub
第一次上传项目代码
# 先删除克隆下来的.git目录
rm -rf .git
# Git 全局设置
git config --global user.name "root"
git config --global user.email "gao15540451242@163.com"
创建一个新仓库
git clone ssh://git@192.168.25.55:222/root/test.git
cd test
touch README.md
git add README.md
git commit -m "add README"
git push -u origin master
推送现有文件夹
cd existing_folder
git init
git remote add origin ssh://git@192.168.25.55:222/root/test.git
git add .
git commit -m "Initial commit"
git push -u origin master
推送现有的 Git 仓库
cd existing_repo
git remote rename origin old-origin
git remote add origin ssh://git@192.168.25.55:222/root/test.git
git push -u origin --all
git push -u origin --tags
推送报错原因:
当前分支的最新提交落后于其对应的远程分支。
解决方法:
我们先从远程库fetch到更新再和本地库合并,之后就可以git push操作了。
git fetch origin
git merge origin/master
评论区