Skip to main content
Sourcegraph supports two primary self-hosted deployment methods. Choose based on your scale and operational capabilities.
Docker ComposeKubernetes (Helm)
Best forSmall to medium teamsLarge enterprises
Node countSingle nodeMulti-node
ScalingVerticalHorizontal
ComplexityLowerHigher
Recommended sizeUp to ~M (5,000 users)Any scale
Changing deployment methods after initial setup requires a full redeployment and database migration. Choose the right method for your long-term needs before going to production.

Docker Compose deployment

Docker Compose runs all Sourcegraph services as containers on a single host. It is easier to operate than Kubernetes and works well for teams up to a few thousand users.

Prerequisites

  • Docker v20.10.0 or later
  • Docker Compose v1.29.0 or later (Docker Swarm mode is not supported)
  • A Linux server with SSD storage (see system requirements)
  • A Sourcegraph Enterprise license for instances with more than 10 users
Running Sourcegraph on Windows or ARM/ARM64 is not supported for production deployments.

Installation

1

Fork the deployment repository

The sourcegraph/deploy-sourcegraph-docker repository contains the docker-compose.yaml and all supporting configuration.Create a private copy of this repository in your own code host. Storing your customizations in version control makes upgrades much simpler — you track changes as a diff against the upstream repository.
# Bare clone the deployment repo
git clone --bare https://github.com/sourcegraph/deploy-sourcegraph-docker/

# Mirror push to your private repository
cd deploy-sourcegraph-docker.git
git push --mirror https://github.com/your-org/sourcegraph-deploy.git

# Clean up the bare clone
cd ..
rm -rf deploy-sourcegraph-docker.git
2

Create a release branch

Clone your private repository and create a release branch pinned to the version you want to install:
git clone https://github.com/your-org/sourcegraph-deploy.git
cd sourcegraph-deploy

# Add the upstream repo so you can pull future releases
git remote add upstream https://github.com/sourcegraph/deploy-sourcegraph-docker

# Check out a release branch from the desired version tag
export SOURCEGRAPH_VERSION=6.5.0
git checkout $SOURCEGRAPH_VERSION -b release
3

Customize the instance

Do not edit docker-compose.yaml directly. Instead, create a docker-compose.override.yaml file in the same directory. The override file is merged with the base config, so your changes survive upstream updates without merge conflicts.Common customizations in the override file:
  • Adjust CPU and memory limits for individual services
  • Add replicas for high-traffic services
  • Connect to an external PostgreSQL or Redis
  • Set environment variables
  • Mount custom TLS certificates
Commit the override file to your release branch.
4

Clone to the production server

On your production server, clone the release branch:
git clone --branch release https://github.com/your-org/sourcegraph-deploy.git
5

Start Sourcegraph

From the docker-compose directory, start all services:
cd docker-compose
docker compose up -d
Check that the frontend is healthy:
docker ps --filter="name=sourcegraph-frontend-0"
Once the sourcegraph-frontend-0 container shows as healthy, navigate to your server’s IP or hostname on port 80. You will be prompted to create the initial site admin account.
6

Apply site configuration

After signing in as the initial admin, go to Site admin > Configuration to set your externalURL, connect code hosts, configure authentication, and add your license key. See Site configuration for details.

Upgrading (Docker Compose)

Upgrades are performed by updating the release branch to a newer version tag and redeploying.
1

Fetch upstream tags

git fetch upstream
2

Merge the new version

export NEW_VERSION=6.6.0
git merge $NEW_VERSION
Resolve any merge conflicts. Your docker-compose.override.yaml should not conflict with the base file.
3

Pull new images and restart

On the production server, pull the updated repository and restart services:
git pull
cd docker-compose
docker compose pull
docker compose up -d
Always read the changelog for the versions you are upgrading through. Some versions require specific migration steps before restarting.

Resource requirements

Use the table below to estimate the resources needed for your deployment. If you fall between sizes, choose the larger one.
SizeUsersRepositoriesvCPUMemoryStorage
XS≤ 500≤ 5,000832 GBSSD
S≤ 1,000≤ 10,0001664 GBSSD
M≤ 5,000≤ 50,00032128 GBSSD
L≤ 10,000≤ 100,00048192 GBSSD
XL≤ 20,000≤ 250,00096384 GBSSD
Recommended cloud instance types:
SizeAWSAzureGCP
XSm6a.2xlargeD8_v3n2-standard-8
Sm6a.4xlargeD16_v3n2-standard-16
Mm6a.8xlargeD32_v3n2-standard-32
Lm6a.12xlargeD48_v3n2-standard-48
XLm6a.24xlargeD64_v3n2-standard-96

After deployment

Once Sourcegraph is running, complete the initial setup:
  1. Set externalURL in site config to your instance’s public URL.
  2. Add code host connections so Sourcegraph can clone and index your repositories.
  3. Configure authentication with your identity provider.
  4. Apply your license key to unlock Enterprise features.
  5. Configure SMTP so Sourcegraph can send email notifications.
See Administration overview and Site configuration for detailed guidance on each step.

Build docs developers (and LLMs) love