Link Search Menu Expand Document
Start for Free

Running Stardog with Docker Compose

This page describes how to run Stardog with Docker Compose.


Overview

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:

  • Declarative Configuration: Define your entire Stardog environment (image version, ports, volumes, environment variables, network settings, restart policies) in a single file.
  • Reproducibility: Easily recreate the exact same environment on different machines or at different times.
  • Simplicity: Manage the entire lifecycle of your Stardog service (start, stop, view logs, check status) with simple commands (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.

Cretaing the docker-compose.yml file

Create a file named docker-compose.yml in a dedicated directory for Stardog. This file will contain the Stardog’s configuration.

Basic example

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).
    • “5820:5820” exposes Stardog’s default port on your host machine. Adjust the host port (the first number) if 5820 is already in use on your host.
  • 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.

Managing Stardog with Docker Compose

Place your docker-compose.yml file in a directory. Navigate to that directory in your terminal and use the following commands:

  • Start Stardog:
    docker compose up
    
    • This creates and starts the stardog service defined in your file. If your volumes don’t exist, they are created.
  • Stop and remove Stardog container:
    docker compose down
    
    • This stops and removes the container(s) defined in the Compose file. Crucially, it does not remove named volumes. Your data persists.
  • Stop and remove Stardog container AND named volumes:
    docker compose down -v
    
    • Same as previous command but also removes named volumes defined in the Compose file (stardog-home in the example above). Use with caution! Your Stardog data will be lost.