Skip to main content
Sourcegraph supports two primary self-hosted deployment methods. Choose based on your scale and operational capabilities.
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.
2

Create a release branch

Clone your private repository and create a release branch pinned to the version you want to install:
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:
5

Start Sourcegraph

From the docker-compose directory, start all services:
Check that the frontend is healthy:
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

2

Merge the 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:
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. Recommended cloud instance types:

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.