docker_gitea使用.md

docker 镜像:https://hub.docker.com/r/gitea/gitea


前篇

由 gogs (作者一人在维护) fork 出来的产物, 有多个维护者, 接收 pr, 所以功能应该是比较好的.

https://blog.wolfogre.com/posts/gogs-vs-gitea/

https://blog.gitea.io/2016/12/welcome-to-gitea/ 这篇说的很明确了, 功能强大很多.


安装

  1. 拉取镜像

    1
    $ docker pull gitea/gitea:latest
  2. 创建目录来作为数据存储的地方

    1
    $ mkdir -p /root/docker_data/gitea/data
  3. 启动实例, 实例内部的 web 端口 3000 不能修改, 否者打不开网页

    1
    $ docker run -d --restart=always --name gitea -p 20022:20022 -p 20080:3000 -v /root/docker_data/gitea/data:/data gitea/gitea:latest
  4. 进入网页初始化配置, http://192.168.1.177:20080/, 随便点个连接就会要求初始化页面

    • ssh 服务域名 : 显示在仓库中 复制 的地址
    • ssh 服务端口 : 仓库 ssh 的端口, 因为启动 docker 实例时映射的端口 20022
    • http 服务端口 : 3000, 这个不能修改, 内部 web 服务监听的就是 3000 端口
    • gitea 基本 url : 显示在仓库中 复制 的地址
  5. 测试一下,

    1. 进入 http://192.168.1.177:20080 web 页面中添加 publickey

    2. 使用命令跑一下是否能 ssh 连接

      1
      2
      $ ssh -T -p 20022 git@192.168.1.177
      ssh: connect to host 192.168.1.177 port 20022: Connection refused

      连接失败

      进入 应用配置 (http://192.168.1.177:20080/admin/config) 中查看配置, 在 SSH 配置使用内置 SSH 服务器 未启用, 监听端口 不是 20022

      进入容器实例中查看端口, 也没有看到 20022 端口

      1
      2
      3
      4
      5
      6
      root@ubuntu:~/docker_data/gitea/data# docker exec -it gitea bash # 进入容器
      bash-5.0# netstat -a # 查看端口情况
      Active Internet connections (servers and established)
      Proto Recv-Q Send-Q Local Address Foreign Address State
      tcp 0 0 :::ssh :::* LISTEN
      tcp 0 0 :::3000 :::* LISTEN
  6. 修改配置文件 gitea/conf/app.ini, 启用 内置 ssh, 参考官方文档: https://docs.gitea.io/zh-cn/config-cheat-sheet/

    然后重启 docker 实例

    1
    2
    3
    4
    5
    6
    7
    8
    root@ubuntu:~/docker_data/gitea/data# vi gitea/conf/app.ini 

    DISABLE_SSH = false
    START_SSH_SERVER = true # 增加这个启用 内置 ssh
    SSH_PORT = 20022
    SSH_LISTEN_PORT = 20022 # 和 SSH_PORT 一直

    root@ubuntu:~/docker_data/gitea/data# docker restart gitea # 重启实例
  7. 在测试一下

    1
    2
    3
    $ ssh -T -p 20022 git@192.168.1.177
    Hi there, root! You've successfully authenticated with the key named 364105996@qq.com, but Gitea does not provide shell access. # ssh 连接成功
    If this is unexpected, please log in with password and setup Gitea under another user.

    也可以进入容器内查看端口

    1
    2
    3
    4
    5
    6
    7
    8
    9
    root@ubuntu:~/docker_data/gitea/data# docker exec -it gitea bash # 进入容器
    bash-5.0# netstat -a # 查看端口情况
    Active Internet connections (servers and established)
    Proto Recv-Q Send-Q Local Address Foreign Address State
    tcp 0 0 0.0.0.0:ssh 0.0.0.0:* LISTEN
    tcp 0 0 :::20022 :::* LISTEN
    tcp 0 0 :::ssh :::* LISTEN
    tcp 0 0 :::3000 :::* LISTEN

    然后就可以 ssh 方式 pull/push 仓库了.