This page describes how to run Stardog with Docker Compose.
Docker Compose is a tool for defining and running multi-container Docker applications. It uses a YAML file (docker-compose.yml) to configure application services, networks, and volumes. While Stardog can be run as a single container using docker run, Docker Compose offers several advantages, especially as your configuration becomes more complex or if you plan to run Stardog alongside other services:
docker-compose up, docker-compose down, etc.).This page explains how to configure and manage a Stardog instance using Docker Compose, focusing on essential configuration and data persistence.
Docker Compose is included with Docker Desktop for Windows and macOS. On Linux, you might need to install it separately. You can see if you have it installed with docker compose version.
docker-compose.yml fileCreate a file named docker-compose.yml in a dedicated directory for Stardog. This file will contain the Stardog's configuration.
This is a minimal example to get a Stardog container running with persistent data using a bind mount:
# docker-compose.yml
version: '3.8'
services:
stardog:
image: stardog/stardog
container_name: my-stardog # Optional: Assigns a specific name to the container
ports:
- "5820:5820" # Map host port 5820 to container port 5820 (Stardog's default port)
volumes:
- /var/opt/stardog:/var/opt/stardog # Mount /var/opt/stardog on the host machine to /var/opt/stardog in the container
Explanations of key options:
image: Specifies the Docker image to use. Always use the official stardog/stardog image.container_name: Assigns a fixed, human-readable name to the container created by this service. If omitted, Compose generates a name.ports: Maps ports between the host machine and the container (HOST:CONTAINER).
volumes: Defines how data is persisted outside the container's lifecycle. See more on persistence here.If you want to use a named volume, you need to populate the volume with a license key (and, optionally, the rest of an existing Stardog home directory) before running docker compose up. This is covered here. Continuing with your previous example docker-compose.yml, add the following stanza:
volumes:
stardog-home: # Defines the named volume managed by Docker
Then, instead of running the version of docker run listed here, run docker compose up.
Place your docker-compose.yml file in a directory. Navigate to that directory in your terminal and use the following commands:
docker compose up
stardog service defined in your file. If your volumes don't exist, they are created.docker compose down
docker compose down -v
stardog-home in the example above). Use with caution! Your Stardog data will be lost.