Forgejo provides [container images](https://codeberg.org/forgejo/-/packages/container/forgejo/versions) for use with Docker or other containerization tools.
The **1.20** tag is set to be the latest patch release, starting with **1.20.1-0**. The **1.20** tag will then be equal to **1.20.2-0** when it is released and so on.
Upgrading from **1.X** to **1.X+1** (for instance from **1.19** to **1.20**) requires a [manual operation and human verification](../upgrade/). However it is possible to use the **X.Y** tag (for instance **1.20**) to get the latest point release automatically.
Here is a sample [docker-compose](https://docs.docker.com/compose/install/) file:
```yaml
version: '3'
networks:
forgejo:
external: false
services:
server:
image: codeberg.org/forgejo/forgejo:1.20
container_name: forgejo
environment:
- USER_UID=1000
- USER_GID=1000
restart: always
networks:
- forgejo
volumes:
- ./forgejo:/data
- /etc/timezone:/etc/timezone:ro
- /etc/localtime:/etc/localtime:ro
ports:
- '3000:3000'
- '222:22'
```
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.
## Configuration
The Forgejo configuration is stored in the `app.ini` file as described
in the [Configuration Cheat Sheet](../config-cheat-sheet). When using
the Forgegjo container image, this file is automatically created if it
does not exist already. In addition it is possible to add settings
using configuration variables. For instance:
```
FORGEJO__repository__ENABLE_PUSH_CREATE_USER=true
```
is the equivalent of adding the following to `app.ini`:
```
[repository]
ENABLE_PUSH_CREATE_USER = true
```
> **NOTE:** it is not possible to use environment variables to remove an existing value, it must be done by editing the `app.ini` file.
In the following each database is shown as part of a `docker-compose` example file, with a `diff like` presentation that highlights additions to the example above.
If no database is configured, it will default to using SQLite.
### MySQL database
```yaml
version: "3"
networks:
forgejo:
external: false
services:
server:
image: codeberg.org/forgejo/forgejo:1.20
container_name: forgejo
environment:
- USER_UID=1000
- USER_GID=1000
+ - FORGEJO__database__DB_TYPE=mysql
+ - FORGEJO__database__HOST=db:3306
+ - FORGEJO__database__NAME=forgejo
+ - FORGEJO__database__USER=forgejo
+ - FORGEJO__database__PASSWD=forgejo
restart: always
networks:
- forgejo
volumes:
- ./forgejo:/data
- /etc/timezone:/etc/timezone:ro
- /etc/localtime:/etc/localtime:ro
ports:
- "3000:3000"
- "222:22"
+ depends_on:
+ - db
+
+ db:
+ image: mysql:8
+ restart: always
+ environment:
+ - MYSQL_ROOT_PASSWORD=forgejo
+ - MYSQL_USER=forgejo
+ - MYSQL_PASSWORD=forgejo
+ - MYSQL_DATABASE=forgejo
+ networks:
+ - forgejo
+ volumes:
+ - ./mysql:/var/lib/mysql
```
### PostgreSQL database
```yaml
version: "3"
networks:
forgejo:
external: false
services:
server:
image: codeberg.org/forgejo/forgejo:1.20
container_name: forgejo
environment:
- USER_UID=1000
- USER_GID=1000
+ - FORGEJO__database__DB_TYPE=postgres
+ - FORGEJO__database__HOST=db:5432
+ - FORGEJO__database__NAME=forgejo
+ - FORGEJO__database__USER=forgejo
+ - FORGEJO__database__PASSWD=forgejo
restart: always
networks:
- forgejo
volumes:
- ./forgejo:/data
- /etc/timezone:/etc/timezone:ro
- /etc/localtime:/etc/localtime:ro
ports:
- "3000:3000"
- "222:22"
+ depends_on:
+ - db
+
+ db:
+ image: postgres:14
+ restart: always
+ environment:
+ - POSTGRES_USER=forgejo
+ - POSTGRES_PASSWORD=forgejo
+ - POSTGRES_DB=forgejo
+ networks:
+ - forgejo
+ volumes:
+ - ./postgres:/var/lib/postgresql/data
```
## Hosting repository data on remote storage systems
You might also mount the data and repository folders on a remote drive such as a
network-attached storage system. While there are a multitude of possible solutions,
we will focus on a somewhat minimal setup with NFS here and explain what
measures have to be taken in general so that the administrators can adapt this to
their individual setup.
We begin to describe a possible setup and will try to highlight all important aspects which
the administrator will have to consider if a different hosting environment is present.
An important assumption for the Forgejo image to make is to own the folders it writes into
and reads from. This is naturally an issue since file-system permissions are a machine-local
concept and don't translate over the network easily.
We assume that a server with the hostname `server` is accessible which has a folder `/respositories`
shared via NFS. Append an entry to your `/etc/exports` like
This will write the configuration into our created `conf` folder and all other data into the `data` folder.
Make sure that `USER_UID` and `USER_GID` match the `anonuid` and `anongid` setting
in the NFS server setting here such that the Forgejo user sees files and folders with the same UID and GID
in the respective folders and thus identifies itself as the sole owner of the folder structure.
Using the `rootless` image here solves another problem resulting from the file-system ownership issue.
If we create ssh keys on the `client` image and save them on the `server`, they too will have `0777` permissions, which is prohibited by `openssh`.
It is important for all involved tools that these files not be writable by just anybody with a login, so you would get you an error if you try to use them.
Changing permissions will also not succeed through the chosen `all_squash` setup, which was necessary to allow a correct ownership
mechanic on the server. To resolve this, we consider the `rootless` image, which embeds the `ssh` server, circumventing the problem entirely.
Note this setup is simple and does not necessarily reflect the reality of your network. User mapping and ownership could be streamlined better with Kerberos, but that is out of the scope of this guide.