How to Install Forgejo with Docker and Migrate from GitHub
Learn how to set up Forgejo with Docker and move your code from GitHub. This simple guide makes switching to a self-hosted platform easy.
Docker
Create a new folder named forgejo:
mkdir ~/docker
cd ~/docker
mkdir forgejo
Create docker-compose.yml:
nano docker-compose.yml
Modify docker-compose.yml and save the changes:
version: '3'
networks:
forgejo:
external: false
services:
server:
image: codeberg.org/forgejo/forgejo:7
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'
NOTECheck the official Forgejo website for the latest docker-compose file to install the most recent version.
(Retrieved from Forgejo documentation on September 6, 2024)
Port 3000 is commonly used for web servers. Use a different port to avoid conflicts with other web servers. Change port from 3000:3000
to 3003:3003
in docker-compose.yml.
Start Docker:
docker compose up -d
Check if containers are running properly:
docker compose ps
Go to Forgejo configuration page at http://example.com:3000 and create your account. To reduce RAM usage, set the database type to SQLite and disable self-registration. Then, save the configuration.
Open Forgejo configuration file:
nano forgejo/gitea/conf/app.ini
Set DISABLE_REGISTRATION
to true
, and add ENABLE_REVERSE_PROXY_AUTHENTICATION = true
in the [service] section and LANDING_PAGE = explore
in the [server] section:
DISABLE_REGISTRATION = true
[service]
ENABLE_REVERSE_PROXY_AUTHENTICATION = true
[server]
LANDING_PAGE = explore
The LANDING_PAGE
setting decides what users see when they go to the home page. It can be set to home
, explore
, organizations
, login
or custom URL /custom or https://example.com/custom.
(Retrieved from Forgejo documentation on September 6, 2024)
Restart Docker:
docker compose down; docker compose up -d
Reverse Proxy
Install Caddy:
sudo apt install caddy
Open Caddyfile:
sudo nano /etc/caddy/Caddyfile
Update Caddyfile:
example.com {
route /git* {
uri strip_prefix /git
redir https://git.{host}{uri}
}
}
git.example.com {
reverse_proxy localhost:3003
}
Restart Caddy:
sudo systemctl restart caddy
Go to Forgejo at https://git.example.com or at https://example.com/git if you prefer using a subpath.
Migrate Repositories from GitHub
Create an access token in GitHub settings. This GitHub documentation provides a step-by-step guide on how to create the token.
Log in to Forgejo.
Click the plus sign (+) in the upper right corner and select New Migration.
Enter GitHub repository URL and your access token, then click Migrate Repository button.