Edit Page

Setup with Docker RESTHeart

Tip
If Docker isn’t your thing, check out the setup section for alternative installation methods.

Docker Images in RESTHeart v9

RESTHeart v9 consolidates Docker images from three variants to two for simplified deployment:

Image Description Startup Memory

softinstigate/restheart:latest

GraalVM-based image with full plugin support (JAR and JavaScript)

2-3 seconds

~256MB minimum

softinstigate/restheart:latest-native

Native binary optimized for Kubernetes (JavaScript plugins only)

<100ms

~64MB minimum

Key Changes from v8:

  • ❌ Removed: OpenJDK-based image (replaced by GraalVM)

  • βœ… Default: GraalVM image is now the standard (latest tag)

  • βœ… Native: Optimized for Kubernetes deployments

  • βœ… Full plugins: Dynamic JAR and JavaScript plugin loading by default

Why This Change?

GraalVM now provides performance and size parity with OpenJDK while offering: - Full plugin functionality enabled by default - Better long-term support and performance - Unified image for most deployment scenarios

Which Image Should I Use?

  • latest - For most deployments, development, and when you need to load custom JAR plugins

  • latest-native - For Kubernetes, serverless, or when you need the fastest possible startup and lowest memory footprint

Important
The native image only supports JavaScript plugins. If you need custom Java/Kotlin plugins, use the GraalVM-based latest image or build a custom native image.

Which Docker Setup Should I Use?

Choose based on your needs:

Setup

Use Case

Complexity

Docker Compose (Recommended)

Most users - includes MongoDB

⭐ Easy

Standalone

Developing custom plugins only

⭐ Easy

MongoDB on localhost

RESTHeart in Docker, MongoDB outside

⭐⭐ Moderate

Network isolated

Production-like security setup

⭐⭐⭐ Advanced

Development (open MongoDB)

Testing with external MongoDB tools

⭐⭐ Moderate

If you’re unsure, use Docker Compose.

Run with docker compose

Note
This is the quickest way to run RESTHeart.

To run both RESTHeart and MongoDB services you can use docker compose. Just copy and paste the following shell command:

$ curl https://raw.githubusercontent.com/SoftInstigate/restheart/master/docker-compose.yml --output docker-compose.yml && docker compose up --attach restheart

Run RESTHeart with Docker in standalone mode

Standalone mode runs RESTHeart without MongoDB. Learn more about when to use standalone mode.

$ docker run -p 8080:8080 -e RHO="/fileRealmAuthenticator/users[userid='admin']/password->'secret';/http-listener/host->'0.0.0.0'" softinstigate/restheart -s
Note
the RHO environment variable sets the password for the user admin. $ docker run -p 8080:8080 -e RHO="/fileRealmAuthenticator/users[userid='admin']/password→'secret';/http-listener/host→'0.0.0.0'" softinstigate/restheart -s
Note
the RHO environment variable sets the password for the user admin.

Run RESTHeart with Docker, MongoDB running on localhost

This runs RESTHeart with Docker connecting to MongoDB running on the localhost.

If MongoDB is not already running, the following command will start a replica set and initiate it (the replica set is not required but enables RESTHeart to support transactions and change streams). Note that the data path is /tmp/db.

$ mkdir -p /tmp/db && mongod --fork --syslog --replSet=foo -dbpath=/tmp/db && mongosh --quiet --eval 'if (!rs.isMaster().ismaster) rs.initiate();'

Run RESTHeart with:

On OSX and Windows:

$ docker run --rm -p "8080:8080" softinstigate/restheart

On Linux

$ docker run --rm -p "8080:8080" --add-host host.docker.internal:host-gateway softinstigate/restheart
Note
This command relies on the docker support of host.docker.internal. If you are using an old docker version or a docker runtime that does not support it, than you need to configure the docker network accordingly (you can refer to the brilliant "From inside of a Docker container, how do I connect to the localhost of the machine?" on StackOverflow) or use one of the an alternative methods described in the further sections.

Run RESTHeart and network isolated MongoDB with Docker

This setup uses a RESTHeart container connecting to a MongoDB container via a private Docker network. This ensures network isolation, with the RESTHeart API as the only entry point. The containers communicate securely within their dedicated network, while external access is controlled through the RESTHeart API

Understanding This Setup

This configuration uses a Docker network to isolate RESTHeart and MongoDB:

  • Both containers communicate via a private network

  • Only RESTHeart’s port (8080) is exposed to your host machine

  • MongoDB is not directly accessible from outside the Docker network

  • This mimics a production security model

Use this setup for: - Learning production deployment patterns - Testing security configurations - Development environments needing network isolation # Setup Procedure

You only need to complete this setup once. Follow these steps:

1) Create a Docker Network

Create a dedicated network for RESTHeart and MongoDB communication:

$ docker network create restheart-network

2) Start MongoDB Container

Launch a MongoDB container within the created network:

$ docker run -d --name mongodb --network restheart-network mongo --replSet=rs0

3) Initialize MongoDB as a Single Node Replica Set

Initialize the MongoDB instance to work as a single node replica set:

$ docker run -it --network restheart-network --rm mongo mongosh --host mongodb --quiet --eval "rs.initiate()"

4) Launch RESTHeart Container

Run the RESTHeart container, linking it to the MongoDB container:

$ docker run --name restheart --rm --network restheart-network -p "8080:8080" -e RHO='/http-listener/host->"0.0.0.0";/mclient/connection-string->"mongodb://mongodb"' softinstigate/restheart

Command breakdown: - --network restheart-network - Connects to the isolated network - -p "8080:8080" - Exposes RESTHeart’s API port - --rm - Automatically removes container on stop (stateless) - -e RHO='…​' - Configures MongoDB connection string to use hostname mongodb (the container name)

5) Test the Setup

Execute a test request to verify that RESTHeart is running:

$ http -b http://localhost:8080/ping
# Expected Output: Greetings from RESTHeart!

Stopping the Containers

To stop both RESTHeart and MongoDB containers, use the following command:

$ docker stop restheart mongodb

Restarting the Containers

The RESTHeart container is stateless and is removed upon stopping (due to the --rm option). However, the MongoDB container retains its state and is not removed on stop. To restart, use the following commands:

1) Start MongoDB Container

$ docker start mongodb

2) Run RESTHeart Container

$ docker run --name restheart --rm --network restheart-network -p 8080:8080 -e RHO='/http-listener/host->"0.0.0.0";/mclient/connection-string->"mongodb://mongodb"' softinstigate/restheart

How to connect to MongoDB with mongosh

$ docker run -it --network restheart-network --rm mongo mongosh --host mongodb

For development: run RESTHeart and open MongoDB with Docker

Warning
This setup is insecure and should be only used for developing or testing purposes.

Setup Procedure

You only need to complete this setup once. Follow these steps:

1) Start MongoDB Container

Launch a MongoDB container:

$ docker run -d --name mongodb -p 27017:27017 mongo --replSet=rs0

2) Initialize MongoDB as a Single Node Replica Set

Initialize the MongoDB instance to work as a single node replica set:

$ docker exec mongodb mongosh --quiet --eval "rs.initiate()"

3) Launch RESTHeart Container

Run the RESTHeart container, linking it to the MongoDB container:

$ docker run --name restheart --rm -p "8080:8080" softinstigate/restheart

4) Test the Setup

Execute a test request to verify that RESTHeart is running:

$ http -b http://localhost:8080/ping
# Expected Output: Greetings from RESTHeart!

Stopping the Containers

To stop both RESTHeart and MongoDB containers, use the following command:

$ docker stop restheart mongodb

Restarting the Containers

The RESTHeart container is stateless and is removed upon stopping (due to the --rm option). However, the MongoDB container retains its state and is not removed on stop. To restart, use the following commands:

1) Start MongoDB Container

$ docker start mongodb

2) Run RESTHeart Container

$ docker run --name restheart --rm -p "8080:8080" softinstigate/restheart

Run RESTHeart with custom plugin

If the plugin jar file is in the directory ./target, this command starts RESTHeart with the plugin integrated:

$ docker run --name restheart --rm -p "8080:8080" -v ./target:/opt/restheart/plugins/custom softinstigate/restheart
Note
This command requires RESTHeart version equal or greater than 7.7.

How this works: - -v ./target:/opt/restheart/plugins/custom mounts your local ./target directory - RESTHeart scans /opt/restheart/plugins/ on startup - Your plugin JAR files in ./target will be loaded automatically

Requirements: - Plugin JAR must be in ./target on your host machine - RESTHeart version must be >= 7.7

Run RESTHeart with remote debugging

This runs RESTHeart enabling remote debugging (port 4000).

$ docker run --rm -p 8080:8080 -p 4000:4000 --entrypoint "java" softinstigate/restheart -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=0.0.0.0:4000 -jar restheart.jar

How to connect to MongoDB with mongosh

$ docker exec -it mongodb mongosh

The RESTHeart Docker tags

RESTHeart Docker images come in four different versions:

Which Docker Tag Should I Use?

For most users: Use latest (the standard image)

Choose a different tag if: - You need JavaScript plugins β†’ Use latest-graalvm - You need smallest image size β†’ Use latest-distroless - You’re deploying to Kubernetes β†’ Use latest-native - You need a specific version β†’ Use version tags like 8.1.5

Docker Tag Reference

  • Standard multi-arch (FROM eclipse-temurin)

  • Graalvm (FROM softinstigate/graalvm)

  • distroless (FROM gcr.io/distroless/java21-debian12)

  • native (FROM debian:12.6-slim)

These are example tags:

Tag

Example

Description

<version>

latest, 8, 8.1, 8.0.1

The standard image. This is usually the one you want to use. Keep in mind it doesn’t support running JavaScript plugins. docker pull softinstigate/restheart:latest

<version>-distroless

latest-distroless, 8-distroless, 8.1-distroless, 8.0.1-distroless

Similar to the standard image, this image contains only RESTHeart and its runtime dependencies. It does not contain a package manager, shells or any other programs you would expect to find in a standard Linux distribution. docker pull softinstigate/restheart:latest-distroless

<version>-graalvm

latest-graalvm, 8-graalvm, 8.1-graalvm, 8.0.1-graalvm

RESTHeart running on the GraalVM that will let you JavaScript plugins. Check out the Plugins in JavaScript for more info. This is the biggest image (about 600Mbytes). docker pull softinstigate/restheart:latest-graalvm

<version>-native

latest-native, 8-native, 8.1-native, 8.0.1-native

RESTHeart built as a native binary. It is the smallest image with lightning-fast startup time. This is the perfect choice for deploying in a Kubernetes cluster. It can only execute JavaScript plugins. Check out Deploy Java plugins on RESTHeart Native for more info. docker pull softinstigate/restheart:latest-native

Dockerfile

The "distroless" images are for special deployment requirements, where having the smallest possible image size and the very minimal security attack surface is required and their tag contains a distroless label. You usually don’t need these images unless you exactly know what you are doing.

Images tags ending with -native are created with the GraalVM Native Image technology starting from stable builds of the product, especially suited for high demanding environments, like Kubernetes. These are experimental and not fully documented yet, please contact us for questions.

What’s Next?

Verify Installation

  1. Open http://localhost:8080/ping - you should see "Greetings from RESTHeart!"

  2. Check Your First Request to make an API call

Learn Core Concepts

Before diving into features, understand how RESTHeart works: - Core Concepts - Architecture and plugin system - Security Fundamentals - Authentication and authorization

Start Building

Choose your learning path: - MongoDB User: REST API Tutorial or GraphQL Tutorial - Plugin Developer: Plugin Development Tutorial - DevOps: Configuration Guide

Load Sample Data

Sample Data provides ready-to-use MongoDB collections for experimenting with the API. - Load the sample data into MongoDB and play with the Data API.