2017-11-26 16:44:32 -05:00
---
2020-05-04 11:50:29 +02:00
date : "2020-03-19T19:27:00+02:00"
2024-08-06 16:44:42 -07:00
2017-11-26 16:44:32 -05:00
slug : "install-with-docker"
2023-07-25 23:53:13 -05:00
sidebar_position : 70
2024-08-06 16:44:42 -07:00
2023-04-27 22:33:41 -05:00
aliases :
- /en-us/install-with-docker
2017-11-26 16:44:32 -05:00
---
# Installation with Docker
2018-01-08 16:48:42 -06:00
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.
2017-11-26 16:44:32 -05:00
2018-10-28 03:18:55 +00:00
This reference setup guides users through the setup based on `docker-compose` , but the installation
2019-03-09 16:15:45 -05:00
of `docker-compose` is out of scope of this documentation. To install `docker-compose` itself, follow
2018-01-08 16:48:42 -06:00
the official [install instructions ](https://docs.docker.com/compose/install/ ).
2017-11-26 16:44:32 -05:00
## Basics
2025-02-28 15:36:37 +00:00
The most simple setup just creates a volume and a network and starts the `docker.gitea.com/gitea:latest`
2019-03-09 16:15:45 -05:00
image as a service. Since there is no database available, one can be initialized using SQLite3.
2018-01-08 16:48:42 -06:00
Create a directory like `gitea` and paste the following content into a file named `docker-compose.yml` .
2018-02-16 01:56:10 +00:00
Note that the volume should be owned by the user/group with the UID/GID specified in the config file.
If you don't give the volume correct permissions, the container may not start.
2024-08-31 23:36:04 -07:00
For a stable release you can use `:latest` , `:1` or specify a certain release like `:@dockerVersion@` , but if you'd like to use the latest development version of Gitea then you could use the `:nightly` tag. If you'd like to run the latest commit from a release branch you can use the `:1.x-nightly` tag, where x is the minor version of Gitea. (e.g. `:1.16-nightly` )
2017-11-26 16:44:32 -05:00
```yaml
2020-10-09 04:31:07 +02:00
version : "3"
2017-11-26 16:44:32 -05:00
networks :
gitea :
external : false
services :
server :
2025-02-28 15:36:37 +00:00
image : docker.gitea.com/gitea:@dockerVersion@
2020-10-09 04:31:07 +02:00
container_name : gitea
2018-02-16 01:56:10 +00:00
environment :
- USER_UID=1000
- USER_GID=1000
2017-11-26 16:44:32 -05:00
restart : always
networks :
- gitea
volumes :
- ./gitea:/data
2019-11-13 13:46:46 +01:00
- /etc/timezone:/etc/timezone:ro
- /etc/localtime:/etc/localtime:ro
2017-11-26 16:44:32 -05:00
ports :
2017-12-05 14:03:40 +08:00
- "3000:3000"
- "222:22"
2017-11-26 16:44:32 -05:00
```
2020-12-09 07:47:06 +01:00
## Ports
2017-11-26 16:44:32 -05:00
2021-12-24 04:56:57 +01:00
To bind the integrated OpenSSH daemon and the webserver on a different port, adjust
2018-01-08 16:48:42 -06:00
the port section. It's common to just change the host port and keep the ports within
the container like they are.
2017-11-26 16:44:32 -05:00
```diff
2020-10-09 04:31:07 +02:00
version: "3"
2017-11-26 16:44:32 -05:00
networks:
gitea:
external: false
services:
server:
2025-02-28 15:36:37 +00:00
image: docker.gitea.com/gitea:@dockerVersion@
2020-10-09 04:31:07 +02:00
container_name: gitea
2018-02-16 01:56:10 +00:00
environment:
- USER_UID=1000
- USER_GID=1000
2017-11-26 16:44:32 -05:00
restart: always
networks:
- gitea
volumes:
- ./gitea:/data
2019-11-13 13:46:46 +01:00
- /etc/timezone:/etc/timezone:ro
- /etc/localtime:/etc/localtime:ro
2017-11-26 16:44:32 -05:00
ports:
2020-12-17 13:00:43 +08:00
- - "3000:3000"
- - "222:22"
+ - "8080:3000"
+ - "2221:22"
2017-11-26 16:44:32 -05:00
```
2020-12-09 07:47:06 +01:00
## Databases
### MySQL database
2017-11-26 16:44:32 -05:00
2018-01-08 16:48:42 -06:00
To start Gitea in combination with a MySQL database, apply these changes to the
`docker-compose.yml` file created above.
2017-11-26 16:44:32 -05:00
```diff
2020-10-09 04:31:07 +02:00
version: "3"
2017-11-26 16:44:32 -05:00
networks:
gitea:
external: false
services:
server:
2025-02-28 15:36:37 +00:00
image: docker.gitea.com/gitea:@dockerVersion@
2020-10-09 04:31:07 +02:00
container_name: gitea
2018-02-16 01:56:10 +00:00
environment:
- USER_UID=1000
- USER_GID=1000
2022-12-20 16:26:03 -06:00
+ - GITEA__database__DB_TYPE=mysql
+ - GITEA__database__HOST=db:3306
+ - GITEA__database__NAME=gitea
+ - GITEA__database__USER=gitea
+ - GITEA__database__PASSWD=gitea
2017-11-26 16:44:32 -05:00
restart: always
networks:
- gitea
volumes:
- ./gitea:/data
2019-11-13 13:46:46 +01:00
- /etc/timezone:/etc/timezone:ro
- /etc/localtime:/etc/localtime:ro
2022-01-11 14:33:42 +03:00
ports:
- "3000:3000"
- "222:22"
2017-11-26 16:44:32 -05:00
+ depends_on:
+ - db
+
+ db:
2024-12-17 20:23:46 +00:00
+ image: docker.io/library/mysql:8
2017-11-26 16:44:32 -05:00
+ restart: always
+ environment:
+ - MYSQL_ROOT_PASSWORD=gitea
+ - MYSQL_USER=gitea
+ - MYSQL_PASSWORD=gitea
+ - MYSQL_DATABASE=gitea
+ networks:
+ - gitea
+ volumes:
+ - ./mysql:/var/lib/mysql
```
2020-12-09 07:47:06 +01:00
### PostgreSQL database
2017-11-26 16:44:32 -05:00
2018-01-08 16:48:42 -06:00
To start Gitea in combination with a PostgreSQL database, apply these changes to
the `docker-compose.yml` file created above.
2017-11-26 16:44:32 -05:00
```diff
2020-10-09 04:31:07 +02:00
version: "3"
2017-11-26 16:44:32 -05:00
networks:
gitea:
external: false
services:
server:
2025-02-28 15:36:37 +00:00
image: docker.gitea.com/gitea:@dockerVersion@
2020-10-09 04:31:07 +02:00
container_name: gitea
2018-02-16 01:56:10 +00:00
environment:
- USER_UID=1000
- USER_GID=1000
2022-12-20 16:26:03 -06:00
+ - GITEA__database__DB_TYPE=postgres
+ - GITEA__database__HOST=db:5432
+ - GITEA__database__NAME=gitea
+ - GITEA__database__USER=gitea
+ - GITEA__database__PASSWD=gitea
2017-11-26 16:44:32 -05:00
restart: always
networks:
- gitea
volumes:
- ./gitea:/data
2019-11-13 13:46:46 +01:00
- /etc/timezone:/etc/timezone:ro
- /etc/localtime:/etc/localtime:ro
2018-02-16 01:56:10 +00:00
ports:
- "3000:3000"
- "222:22"
2017-11-26 16:44:32 -05:00
+ depends_on:
+ - db
+
+ db:
2024-12-17 20:23:46 +00:00
+ image: docker.io/library/postgres:14
2017-11-26 16:44:32 -05:00
+ restart: always
+ environment:
+ - POSTGRES_USER=gitea
+ - POSTGRES_PASSWORD=gitea
+ - POSTGRES_DB=gitea
+ networks:
+ - gitea
+ volumes:
+ - ./postgres:/var/lib/postgresql/data
```
## Named volumes
2018-01-08 16:48:42 -06:00
To use named volumes instead of host volumes, define and use the named volume
within the `docker-compose.yml` configuration. This change will automatically
2018-02-16 01:56:10 +00:00
create the required volume. You don't need to worry about permissions with
2019-03-09 16:15:45 -05:00
named volumes; Docker will deal with that automatically.
2017-11-26 16:44:32 -05:00
```diff
2020-10-09 04:31:07 +02:00
version: "3"
2017-11-26 16:44:32 -05:00
networks:
gitea:
external: false
+volumes:
+ gitea:
+ driver: local
+
services:
server:
2025-02-28 15:36:37 +00:00
image: docker.gitea.com/gitea:@dockerVersion@
2020-10-09 04:31:07 +02:00
container_name: gitea
2017-11-26 16:44:32 -05:00
restart: always
networks:
- gitea
volumes:
2022-12-20 16:26:03 -06:00
- - ./gitea:/data
+ - gitea:/data
2019-11-13 13:46:46 +01:00
- /etc/timezone:/etc/timezone:ro
- /etc/localtime:/etc/localtime:ro
2017-11-26 16:44:32 -05:00
ports:
2017-12-05 14:03:40 +08:00
- "3000:3000"
- "222:22"
2017-11-26 16:44:32 -05:00
```
2018-01-08 16:48:42 -06:00
MySQL or PostgreSQL containers will need to be created separately.
2017-11-26 16:44:32 -05:00
2020-12-09 07:47:06 +01:00
## Startup
2017-11-26 16:44:32 -05:00
2024-08-03 03:08:33 +00:00
:::note
From July 2023 Compose V1 stopped receiving updates. It's also no longer available in new releases of Docker Desktop.
Compose V2 is included with all currently supported versions of Docker Desktop. Please use V2 to do below operations.
:::
2018-01-08 16:48:42 -06:00
To start this setup based on `docker-compose` , execute `docker-compose up -d` ,
to launch Gitea in the background. Using `docker-compose ps` will show if Gitea
started properly. Logs can be viewed with `docker-compose logs` .
2017-11-26 16:44:32 -05:00
2018-01-08 16:48:42 -06:00
To shut down the setup, execute `docker-compose down` . This will stop
and kill the containers. The volumes will still exist.
2017-11-26 16:44:32 -05:00
2024-06-07 18:03:08 +08:00
:::note
If using a non-3000 port on http, change app.ini to match
2018-01-08 16:48:42 -06:00
`LOCAL_ROOT_URL = http://localhost:3000/` .
2024-06-07 18:03:08 +08:00
:::
2017-11-30 19:18:35 +08:00
2020-12-09 07:47:06 +01:00
## Installation
2017-11-26 16:44:32 -05:00
2019-03-09 16:15:45 -05:00
After starting the Docker setup via `docker-compose` , Gitea should be available using a
2018-01-08 16:48:42 -06:00
favorite browser to finalize the installation. Visit http://server-ip:3000 and follow the
installation wizard. If the database was started with the `docker-compose` setup as
2019-03-09 16:15:45 -05:00
documented above, please note that `db` must be used as the database hostname.
2017-11-26 16:44:32 -05:00
2022-07-28 03:22:47 +02:00
## Configure the user inside Gitea using environment variables
2018-04-17 02:56:28 +02:00
2021-04-12 15:42:02 -04:00
- `USER` : **git** : The username of the user that runs Gitea within the container.
2020-12-09 07:47:06 +01:00
- `USER_UID` : **1000** : The UID (Unix user ID) of the user that runs Gitea within the container. Match this to the UID of the owner of the `/data` volume if using host volumes (this is not necessary with named volumes).
- `USER_GID` : **1000** : The GID (Unix group ID) of the user that runs Gitea within the container. Match this to the GID of the owner of the `/data` volume if using host volumes (this is not necessary with named volumes).
2018-04-17 02:56:28 +02:00
2020-12-09 07:47:06 +01:00
## Customization
2017-11-26 16:44:32 -05:00
2024-06-14 05:53:15 +00:00
Customization files described [here ](../administration/customizing-gitea.md ) should
2019-03-09 16:15:45 -05:00
be placed in `/data/gitea` directory. If using host volumes, it's quite easy to access these
files; for named volumes, this is done through another container or by direct access at
2018-01-08 16:48:42 -06:00
`/var/lib/docker/volumes/gitea_gitea/_data` . The configuration file will be saved at
`/data/gitea/conf/app.ini` after the installation.
2018-11-26 14:51:02 +13:00
2020-12-09 07:47:06 +01:00
## Upgrading
2018-11-26 14:51:02 +13:00
2024-06-07 18:03:08 +08:00
:::warning
2019-04-05 10:01:38 -05:00
:exclamation::exclamation: **Make sure you have volumed data to somewhere outside Docker container** :exclamation::exclamation:
2024-06-07 18:03:08 +08:00
:::
2018-11-26 14:51:02 +13:00
To upgrade your installation to the latest release:
2020-12-03 00:23:54 +01:00
```bash
2018-11-26 14:51:02 +13:00
# Edit `docker-compose.yml` to update the version, if you have one specified
# Pull new images
docker-compose pull
# Start a new container, automatically removes old one
docker-compose up -d
```
2019-01-05 17:53:23 +00:00
2021-02-23 14:21:44 -05:00
## Managing Deployments With Environment Variables
2023-05-24 11:37:22 +08:00
In addition to the environment variables above, any settings in `app.ini` can be set
or overridden with an environment variable of the form: `GITEA__SECTION_NAME__KEY_NAME` .
2023-07-10 06:43:37 +08:00
These settings are applied each time the docker container starts, and won't be passed into Gitea's sub-processes.
2023-05-24 11:37:22 +08:00
Full information [here ](https://github.com/go-gitea/gitea/tree/master/contrib/environment-to-ini ).
2021-02-23 14:21:44 -05:00
2023-05-24 11:37:22 +08:00
These environment variables can be passed to the docker container in `docker-compose.yml` .
The following example will enable an smtp mail server if the required env variables
`GITEA__mailer__FROM` , `GITEA__mailer__HOST` , `GITEA__mailer__PASSWD` are set on the host
or in a `.env` file in the same directory as `docker-compose.yml` .
The settings can be also set or overridden with the content of a file by defining an environment variable of the form:
`GITEA__section_name__KEY_NAME__FILE` that points to a file.
2021-02-23 14:21:44 -05:00
```bash
...
services:
server:
environment:
2022-12-20 16:26:03 -06:00
- GITEA__mailer__ENABLED = true
- GITEA__mailer__FROM = ${ GITEA__mailer__FROM :?GITEA__mailer__FROM not set }
2023-07-26 15:50:15 +02:00
- GITEA__mailer__PROTOCOL = smtps
2024-04-04 01:16:02 +02:00
- GITEA__mailer__SMTP_ADDR = ${ GITEA__mailer__SMTP_ADDR :?GITEA__mailer__SMTP_ADDR not set }
- GITEA__mailer__SMTP_PORT = ${ GITEA__mailer__SMTP_PORT :?GITEA__mailer__SMTP_PORT not set }
2022-12-20 16:26:03 -06:00
- GITEA__mailer__USER = ${ GITEA__mailer__USER :- apikey }
- GITEA__mailer__PASSWD = """ ${ GITEA__mailer__PASSWD :?GITEA__mailer__PASSWD not set } """
2021-02-23 14:21:44 -05:00
```
2024-06-14 05:53:15 +00:00
Gitea will generate new secrets/tokens for every new installation automatically and write them into the app.ini. If you want to set the secrets/tokens manually, you can use the following docker commands to use of Gitea's built-in [generate utility functions ](../administration/command-line.md#generate ). Do not lose/change your SECRET_KEY after the installation, otherwise the encrypted data can not be decrypted anymore.
2022-07-30 01:28:50 -04:00
The following commands will output a new `SECRET_KEY` and `INTERNAL_TOKEN` to `stdout` , which you can then place in your environment variables.
```bash
2025-02-28 15:36:37 +00:00
docker run -it --rm docker.gitea.com/gitea:1 gitea generate secret SECRET_KEY
docker run -it --rm docker.gitea.com/gitea:1 gitea generate secret INTERNAL_TOKEN
2022-07-30 01:28:50 -04:00
```
```yaml
...
services :
server :
environment :
- GITEA__security__SECRET_KEY=[value returned by generate secret SECRET_KEY]
- GITEA__security__INTERNAL_TOKEN=[value returned by generate secret INTERNAL_TOKEN]
```