Single-container Sourcegraph with Docker is a way to very quickly get an instance of Sourcegraph set up locally to experiment with its features.
WARNING: We do not recommend using this method for a production instance. If deploying a production instance, see our recommendations for how to choose a deployment type that suits your needs. We recommend Docker Compose for most initial production deployments.
It takes less than a minute to run and install Sourcegraph using Docker:
docker run --publish 7080:7080 --publish 127.0.0.1:3370:3370 --rm --volume ~/.sourcegraph/config:/etc/sourcegraph --volume ~/.sourcegraph/data:/var/opt/sourcegraph sourcegraph/server:3.37.0
Once the server is ready (logo is displayed in the terminal), navigate to the hostname or IP address on port 7080
. Create the admin account, then you'll be guided through setting up Sourcegraph for code searching and navigation.
For next steps and further configuration options, visit the site administration documentation.
WARNING: We do not recommend using this method for a production instance. If deploying a production instance, see our recommendations for how to choose a deployment type that suits your needs. We recommend Docker Compose for most initial production deployments.
NOTE: If you get stuck or need help, file an issue, tweet (@sourcegraph) or email.
NOTE: If you run Docker on an OS such as RHEL, Fedora, or CentOS with SELinux enabled, sVirt doesn't allow the Docker process to access
~/.sourcegraph/config
and~/.sourcegraph/data
. In that case, you will see the following message:
Failed to setup nginx:failed to generate nginx configuration to /etc/sourcegraph: open /etc/sourcegraph/nginx.conf: permission denied
.
To fix this, run:
mkdir -p ~/.sourcegraph/config ~/.sourcegraph/data && chown -R -t svirt_sandbox_file_t ~/.sourcegraph/config ~/.sourcegraph/data
Cloud specific Sourcegraph installation guides for AWS, Google Cloud and Digital Ocean.
- Install Sourcegraph with Docker on AWS
- Install Sourcegraph with Docker on Google Cloud
- Install Sourcegraph with Docker on DigitalOcean
There is a known issue in Docker for Mac that causes slower than expected file system performance on volume mounts, which impacts the performance of search and cloning.
To achieve better performance, you can do any of the following:
- For better clone performance, clone the repository on your host machine and then add it to Sourcegraph Server.
- Try adding the
:delegated
suffix the data volume mount. Learn more.--volume ~/.sourcegraph/data:/var/opt/sourcegraph:delegated
Sourcegraph can be tested on Windows 10 using roughly the same steps provided above, but data will not be retained after server restarts (this is due to a limitation of Docker on Windows).
- Install Docker for Windows
- Using a command prompt, follow the same installation steps provided above but remove the
--volume
arguments. For example by pasting this:
docker run --publish 7080:7080 --publish 127.0.0.1:3370:3370 --rm sourcegraph/server:3.37.0
To test Sourcegraph in a low resource environment you may want to disable some of the observability tools (Prometheus, Grafana and Jaeger).
Add -e DISABLE_OBSERVABILITY=true
to your docker run command.
In order to restore a Postgres backup, you need to start on an empty database and prevent all other Sourcegraph services from starting.
You can do this by adding -e PGRESTORE=true
to your docker run
command. This will start only the Postgres system and allow you to perform a restore. Once it is done, remove that parameter from your docker command.
The database is only accessible from within the container. To perform a restore you will need to copy the required files to the container and then execute the restore commands from within the container using docker exec
.
You can find examples of this procedure for docker-compose
in our docker-compose migration docs.
To test new development builds of Sourcegraph (triggered by commits to main
), change the tag to insiders
in the docker run
command.
WARNING:
insiders
builds may be unstable, so back up Sourcegraph's data and config (usually~/.sourcegraph
) beforehand.
docker run --publish 7080:7080 --rm --volume ~/.sourcegraph/config:/etc/sourcegraph --volume ~/.sourcegraph/data:/var/opt/sourcegraph sourcegraph/server:insiders
To keep this up to date, run docker pull sourcegraph/server:insiders
to pull in the latest image, and restart the container to access new changes.