docker.recipes

Sourcegraph

advanced

Code search and intelligence platform.

Overview

Sourcegraph is an enterprise-grade code search and navigation platform that provides universal code search across all repositories, programming languages, and version control systems. Originally developed to solve the challenge of finding and understanding code at scale, Sourcegraph has evolved into a comprehensive code intelligence platform used by major tech companies like Uber, Lyft, and Yelp to navigate massive codebases efficiently. The platform combines powerful search capabilities with advanced code intelligence features, enabling developers to quickly locate code, understand dependencies, and make informed changes across large, distributed codebases. This Docker deployment leverages the official Sourcegraph server image to create a single-container instance that includes all necessary components: the web interface, search indexing engine, code intelligence services, and database storage. The configuration provides a complete code search solution that can index repositories from GitHub, GitLab, Bitbucket, and other code hosts, offering features like cross-repository search, semantic code navigation, and automated code insights. This setup is particularly valuable for development teams, engineering managers, and organizations that need to maintain visibility and control over large codebases, enabling faster code reviews, more efficient debugging, and better architectural decision-making through comprehensive code analytics and search capabilities.

Key Features

  • Universal code search across multiple repositories with support for regular expressions, structural search, and symbol-based queries
  • Code intelligence with precise hover tooltips, go-to-definition, and find-references functionality across 40+ programming languages
  • Batch changes system for executing large-scale code modifications and refactoring across multiple repositories simultaneously
  • Integration with major code hosts including GitHub, GitLab, Bitbucket, Phabricator, and Azure DevOps for automatic repository synchronization
  • Code insights dashboard providing visualizations of code metrics, security vulnerabilities, and technical debt patterns
  • Browser extensions for GitHub, GitLab, and other platforms to bring Sourcegraph functionality directly to code review workflows
  • API-driven architecture enabling custom integrations and programmatic access to search and code intelligence features
  • Campaign management for tracking and managing large-scale code changes across organizations with approval workflows

Common Use Cases

  • 1Large engineering organizations needing to search and navigate across hundreds or thousands of repositories
  • 2Security teams conducting code audits and vulnerability assessments across entire codebases
  • 3Development teams performing large-scale refactoring projects that span multiple repositories and services
  • 4Engineering managers tracking code quality metrics and technical debt across development teams
  • 5Open source maintainers managing complex projects with multiple contributors and extensive codebases
  • 6DevOps teams investigating incidents by quickly locating relevant code across microservices architectures
  • 7Code review processes requiring deep context about code changes and their impact across repositories

Prerequisites

  • Minimum 4GB RAM and 2 CPU cores for small to medium codebases (8GB+ recommended for larger deployments)
  • At least 50GB free disk space for code indexing and search data storage
  • Access tokens or credentials for code hosts (GitHub, GitLab, etc.) that will be connected to Sourcegraph
  • Understanding of Git workflows and repository management for configuring code host integrations
  • Network connectivity to external code repositories for initial indexing and ongoing synchronization
  • Basic knowledge of search syntax and regular expressions to effectively utilize advanced search features

For development & testing. Review security settings, change default credentials, and test thoroughly before production use. See Terms

docker-compose.yml

docker-compose.yml
1services:
2 sourcegraph:
3 image: sourcegraph/server:latest
4 container_name: sourcegraph
5 restart: unless-stopped
6 volumes:
7 - sourcegraph_config:/etc/sourcegraph
8 - sourcegraph_data:/var/opt/sourcegraph
9 ports:
10 - "7080:7080"
11 environment:
12 SRC_LOG_LEVEL: info
13
14volumes:
15 sourcegraph_config:
16 sourcegraph_data:

.env Template

.env
1# Configure repositories via web UI

Usage Notes

  1. 1Docs: https://docs.sourcegraph.com/
  2. 2Access at http://localhost:7080 - setup wizard on first visit
  3. 3Add code hosts: Site admin > External services
  4. 4Cross-repository code search with regex support
  5. 5Code intelligence: hover, go to definition, find references
  6. 6Batch changes for large-scale refactoring

Quick Start

terminal
1# 1. Create the compose file
2cat > docker-compose.yml << 'EOF'
3services:
4 sourcegraph:
5 image: sourcegraph/server:latest
6 container_name: sourcegraph
7 restart: unless-stopped
8 volumes:
9 - sourcegraph_config:/etc/sourcegraph
10 - sourcegraph_data:/var/opt/sourcegraph
11 ports:
12 - "7080:7080"
13 environment:
14 SRC_LOG_LEVEL: info
15
16volumes:
17 sourcegraph_config:
18 sourcegraph_data:
19EOF
20
21# 2. Create the .env file
22cat > .env << 'EOF'
23# Configure repositories via web UI
24EOF
25
26# 3. Start the services
27docker compose up -d
28
29# 4. View logs
30docker compose logs -f

One-Liner

Run this command to download and set up the recipe in one step:

terminal
1curl -fsSL https://docker.recipes/api/recipes/sourcegraph/run | bash

Troubleshooting

  • Repository sync failing with authentication errors: Verify code host tokens have correct permissions and haven't expired in Site admin > External services
  • Search results showing outdated code: Check repository sync status and manually trigger re-indexing from the repository settings page
  • High memory usage causing container restarts: Increase Docker memory limits or reduce the number of repositories being indexed simultaneously
  • Code intelligence not working for specific languages: Ensure language servers are enabled in site configuration and repositories have been fully indexed
  • Slow search performance on large codebases: Configure search indexing settings and consider excluding binary files or large data directories
  • Browser extension not connecting to Sourcegraph instance: Verify the Sourcegraph URL is accessible and CORS settings allow browser extension connections

Community Notes

Loading...
Loading notes...

Download Recipe Kit

Get all files in a ready-to-deploy package

Includes docker-compose.yml, .env template, README, and license

Components

sourcegraph

Tags

#sourcegraph#code-search#intelligence#navigation

Category

Development Tools
Ad Space