docker搭建gitlab

1. 搭建gitlab

shell 复制代码
# 1. 获取镜像
docker pull gitlab/gitlab-ce:latest

# 2. 创建并启动容器
# 映射了2个端口,都是需要用到的
docker run -itd -p 9980:80 -p 9922:22 --restart always --privileged=true --name gitlab gitlab/gitlab-ce
# 进入容器
docker exec -it gitlab /bin/bash

# 3. 修改配置
vi /etc/gitlab/gitlab.rb
# 增加以下条配置,docker主机的ip是192.168.1.190,ssh端口号9922
external_url '192.168.1.190'
gitlab_rails['gitlab_ssh_host'] = '192.168.1.190'
gitlab_rails['gitlab_shell_ssh_port'] = 9922

#退出保存,使配置生效
gitlab-ctl reconfigure

# 继续修改
vi /opt/gitlab/embedded/service/gitlab-rails/config/gitlab.yml
# 找到以下配置,并修改
  gitlab:
    ## Web server settings (note: host is the FQDN, do not include http://)
    host: 192.168.1.190
    port: 9980
    https: false


# 重启gitlab
gitlab-ctl restart

# 4. 设置root用户密码
gitlab-rails console
user = User.where(id:1).first
# 设置密码
user.password='12345678'
user.save

# 到此,配置ok

2. 配置ssh

  1. 生成ssh密钥
shell 复制代码
ssh-genkey -t ecdsa -C "邮箱地址"

然后一直确认就可以,建议不要用-t rsa,openssh不建议使用,好多问题。

会在~/.ssh/下生成两个文件:id_ecdsa、id_ecdsa.pub

  1. 创建用户

使用root用户登陆 http://192.168.1.190:9980,创建用户,账号邮箱需与生成ssh时的一致。

  1. 用户设置ssh
    使用新创建的用户登陆gitlab,进入 http://192.168.1.190:9980/-/profile/keys ,添加key,将 id_ecdsa.pub 中的内容填入即可。

3. 创建仓库并同步

git全局设置

shell 复制代码
git config --global user.name "名称"
git config --global user.email "邮箱"

git单项目设置(适合不同项目不同用户名称使用)

shell 复制代码
git config user.name "名称"
git config user.email "邮箱"

创建新仓库

shell 复制代码
git clone ssh://git@192.168.1.190:9922/android/rk3568-app.git
cd rk3568-app
git switch --create main
touch README.md
git add README.md
git commit -m "add README"
git push --set-upstream origin main

将文件夹push到空仓库

shell 复制代码
cd existing_folder
git init --initial-branch=main
git remote add origin ssh://git@192.168.1.190:9922/android/rk3568-app.git
git add .
git commit -m "Initial commit"
git push --set-upstream origin main

将文件夹push到已存在的仓库

shell 复制代码
cd existing_repo
git remote rename origin old-origin
git remote add origin ssh://git@192.168.1.190:9922/android/rk3568-app.git
git push --set-upstream origin --all
git push --set-upstream origin --tags

关联远程仓库

shell 复制代码
git init --initial-branch=main
git remote add origin ssh://git@192.168.1.190:9922/android/rk3568-app.git
git fetch

# 拉取远程库
git checkout -b main origin/main
git pull origin main
相关推荐
铁板鱿鱼14024 分钟前
docker基本(仅供自己参考)
运维·docker·容器
江池俊2 小时前
本地快速部署一个简洁美观的个人Halo博客网站并发布公网远程访问
docker·个人博客
admin_2332 小时前
docker入门总结(附错误处理,持续更新)
运维·docker·容器
linux修理工2 小时前
docker desktop windows stop
docker
Ceder1c2 小时前
【已解决】Linux ubuntu 20.04 docker 不需要sudo权限
linux·ubuntu·docker
hybaym3 小时前
Docker修改默认的存储路径
docker
EricWang13585 小时前
【无标题】
docker
IT空门:门主6 小时前
完整版:NacosDocker 安装
docker
___波子 Pro Max.12 小时前
Docker镜像和容器
docker
小小的木头人17 小时前
Docker vs. containerd 深度剖析容器运行时
运维·docker·容器