Installation with Docker
Gitea provides automatically updated Docker images within its Docker Hub organization. It is possible to always use the latest stable tag or to use another service that handles updating Docker images.
The rootless image uses Gitea internal SSH to provide Git protocol and doesn't support OpenSSH.
This reference setup guides users through the setup based on docker-compose
, but the installation
of docker-compose
is out of scope of this documentation. To install docker-compose
itself, follow
the official install instructions.
Basics
The most simple setup just creates a volume and a network and starts the gitea/gitea:latest-rootless
image as a service. Since there is no database available, one can be initialized using SQLite3.
Create a directory for data
and config
:
mkdir -p gitea/{data,config}
cd gitea
touch docker-compose.yml
Then paste the following content into a file named docker-compose.yml
:
version: "2"
services:
server:
image: gitea/gitea:main-nightly-rootless
restart: always
volumes:
- ./data:/var/lib/gitea
- ./config:/etc/gitea
- /etc/timezone:/etc/timezone:ro
- /etc/localtime:/etc/localtime:ro
ports:
- "3000:3000"
- "2222:2222"
Note that the volume should be owned by the user/group with the UID/GID specified in the config file. By default Gitea in docker will use uid:1000 gid:1000. If needed you can set ownership on those folders with the command:
sudo chown 1000:1000 config/ data/
If you don't give the volume correct permissions, the container may not start.
For a stable release you could use :latest-rootless
, :1-rootless
or specify a certain release like :main-nightly-rootless
, but if you'd like to use the latest development version then :nightly-rootless
would be an appropriate tag. If you'd like to run the latest commit from a release branch you can use the :1.x-nightly-rootless
tag, where x is the minor version of Gitea. (e.g. :1.16-nightly-rootless
)
Custom port
To bind the integrated ssh and the webserver on a different port, adjust the port section. It's common to just change the host port and keep the ports within the container like they are.
version: "2"
services:
server:
image: gitea/gitea:main-nightly-rootless
restart: always
volumes:
- ./data:/var/lib/gitea
- ./config:/etc/gitea
- /etc/timezone:/etc/timezone:ro
- /etc/localtime:/etc/localtime:ro
ports:
- - "3000:3000"
- - "2222:2222"
+ - "80:3000"
+ - "22:2222"
MySQL database
To start Gitea in combination with a MySQL database, apply these changes to the
docker-compose.yml
file created above.
version: "2"
services:
server:
image: gitea/gitea:main-nightly-rootless
+ environment:
+ - GITEA__database__DB_TYPE=mysql
+ - GITEA__database__HOST=db:3306
+ - GITEA__database__NAME=gitea
+ - GITEA__database__USER=gitea
+ - GITEA__database__PASSWD=gitea
restart: always
volumes:
- ./data:/var/lib/gitea
- ./config:/etc/gitea
- /etc/timezone:/etc/timezone:ro
- /etc/localtime:/etc/localtime:ro
ports:
- "3000:3000"
- "2222:2222"
+ depends_on:
+ - db
+
+ db:
+ image: mysql:8
+ restart: always
+ environment:
+ - MYSQL_ROOT_PASSWORD=gitea
+ - MYSQL_USER=gitea
+ - MYSQL_PASSWORD=gitea
+ - MYSQL_DATABASE=gitea
+ volumes:
+ - ./mysql:/var/lib/mysql
PostgreSQL database
To start Gitea in combination with a PostgreSQL database, apply these changes to
the docker-compose.yml
file created above.
version: "2"
services:
server:
image: gitea/gitea:main-nightly-rootless
environment:
+ - GITEA__database__DB_TYPE=postgres
+ - GITEA__database__HOST=db:5432
+ - GITEA__database__NAME=gitea
+ - GITEA__database__USER=gitea
+ - GITEA__database__PASSWD=gitea
restart: always
volumes:
- ./data:/var/lib/gitea
- ./config:/etc/gitea
- /etc/timezone:/etc/timezone:ro
- /etc/localtime:/etc/localtime:ro
ports:
- "3000:3000"
- "2222:2222"
+ depends_on:
+ - db
+
+ db:
+ image: postgres:14
+ restart: always
+ environment:
+ - POSTGRES_USER=gitea
+ - POSTGRES_PASSWORD=gitea
+ - POSTGRES_DB=gitea
+ volumes:
+ - ./postgres:/var/lib/postgresql/data
Named volumes
To use named volumes instead of host volumes, define and use the named volume
within the docker-compose.yml
configuration. This change will automatically
create the required volume. You don't need to worry about permissions with
named volumes; Docker will deal with that automatically.
version: "2"
+volumes:
+ gitea-data:
+ driver: local
+ gitea-config:
+ driver: local
+
services:
server:
image: gitea/gitea:main-nightly-rootless
restart: always
volumes:
- - ./data:/var/lib/gitea
+ - gitea-data:/var/lib/gitea
- - ./config:/etc/gitea
+ - gitea-config:/etc/gitea
- /etc/timezone:/etc/timezone:ro
- /etc/localtime:/etc/localtime:ro
ports:
- "3000:3000"
- "2222:2222"
MySQL or PostgreSQL containers will need to be created separately.
Custom user
You can choose to use a custom user (following --user flag definition https://docs.docker.com/engine/reference/run/#user).
As an example to clone the host user git
definition use the command id -u git
and add it to docker-compose.yml
file:
Please make sure that the mounted folders are writable by the user.
version: "2"
services:
server:
image: gitea/gitea:main-nightly-rootless
restart: always
+ user: 1001
volumes:
- ./data:/var/lib/gitea
- ./config:/etc/gitea
- /etc/timezone:/etc/timezone:ro
- /etc/localtime:/etc/localtime:ro
ports:
- "3000:3000"
- "2222:2222"