Skip to content

gitea

docker-componse

postgres

yaml
version: '3'

networks:
  gitea:
    external: false

volumes:
  gitea:
    driver: local

services:
  server:
    image: gitea/gitea:1.17.2
    container_name: gitea
    environment:
      - USER_UID=1000
      - USER_GID=1000
      - GITEA__database__DB_TYPE=postgres
      - GITEA__database__HOST=db:5432
      - GITEA__database__NAME=gitea
      - GITEA__database__USER=gitea
      - GITEA__database__PASSWD=gitea
    restart: always
    networks:
      - gitea
    volumes:
      - gitea:/data
      - /etc/timezone:/etc/timezone:ro
      - /etc/localtime:/etc/localtime:ro
    ports:
      - '80:3000'
      - '222:22'
    depends_on:
      - db

  db:
    image: postgres:14
    restart: always
    environment:
      - POSTGRES_USER=gitea
      - POSTGRES_PASSWORD=gitea
      - POSTGRES_DB=gitea
    networks:
      - gitea
    volumes:
      - ./postgres:/var/lib/postgresql/data

docker-componse 外部数据库

postgres

若使用 git 协议免密码克隆,如:git clone git@ip:name/repo.git

建议修改宿主机的 ssh 端口为非标准端口,gitea 容器映射端口为标准端口 22

yml
version: '3'

networks:
  gitea:
    external: false

services:
  server:
    image: gitea/gitea:1.18.3
    container_name: gitea
    environment:
      - USER_UID=1000
      - USER_GID=1000
      - GITEA__database__DB_TYPE=postgres
      - GITEA__database__HOST=10.10.135.277:5432
      - GITEA__database__NAME=gitea
      - GITEA__database__USER=postgres
      - GITEA__database__PASSWD=postgres
    restart: always
    networks:
      - gitea
    volumes:
      - ./gitea:/data
      - /etc/timezone:/etc/timezone:zh
      - /etc/localtime:/etc/localtime:zh
    ports:
      - '80:3000'
      - '22:22'

gitea端口映射

Gitea clone git Gitea 使用 git 协议,免密码克隆,需要密码

error

bash
git clone git@10.0.235.288:www/xmi-web.git
Cloning into 'xmi-web'...
git@10.0.235.288's password:
Permission denied, please try again.
git@10.0.235.288's password:
Permission denied, please try again.
git@10.0.235.288's password:
git@10.0.235.288: Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

原因

这个是 ssh 端口问题造成的。gitea 是 docker 安装的,宿主机 ssh 端口 22,gitea 容器里 ssh 是 2222。git clone git@10.0.235.288:www/xmi-web.git, 默认是 22,所有...

解决方法

  1. 使用非标准 SSH 端口连接
bash

git clone ssh://git@hostname:port/.../xxx.git

举例如下:
git clone ssh://git@10.137.20.113:2222/root/test.git
  1. 修改宿主机的 ssh 端口为非标准 ssh 端口,容器映射时 ssh 映射 22 端口

在 centos9/redhat9/almalinux9/rockylinux9 系统

bash
vi /etc/ssh/sshd_config

#Port 22
Port 2222

重启 ssh

bash
systemctl restart sshd

重启 ssh bug

如果出现

bash
Bind to port 2222 on 0.0.0.0 failed: Permission denied

请关闭 selinux

bash
setenforce 0