Install SurrealDB Inside Docker Container on Linux

Install SurrealDB Inside Docker Container on Linux

SurrealDB is a versatile database designed to simplify backend development by combining features of traditional relational, document, graph, and key-value databases. It provides real-time queries, built-in authentication, and native support for structured and unstructured data without needing additional backend services.

This tutorial explains how to install SurrealDB inside a Docker container on Linux. Commands have been tested on Ubuntu.

Prepare environment

Make sure you have installed Docker in your system. If you are using Ubuntu, installation instructions can be found in the post.

Install SurrealDB

Before starting, create directory for data:

sudo mkdir -p /opt/surrealdb/data

Set user, which ID is 65532 as owner for newly created directory:

sudo chown -R 65532:65532 /opt/surrealdb

Note: it doesn't matter that user (ID: 65532) doesn't exist on host system. This user will be created in the container.

  • Host network

Run the following command to create a container for SurrealDB that uses host network:

docker run -d --name=surrealdb --restart=always --network=host \
    -v /opt/surrealdb/data:/data \
    surrealdb/surrealdb start rocksdb:/data/mydatabase.db
  • User-defined bridge network

User-defined bridge network can be used for listening on different port. By default, SurrealDB service is listening on port 8000. It can be changed with -p option.

docker network create app-net
docker run -d --name=surrealdb --restart=always --network=app-net \
    -p 8080:8000 \
    -v /opt/surrealdb/data:/data \
    surrealdb/surrealdb start rocksdb:/data/mydatabase.db

Testing SurrealDB

Send a GET request to check if the SurrealDB service is running:

curl http://<IP_ADDRESS>:8000/version

This endpoint returns SurrealDB version.

Note: Replace <IP_ADDRESS> with the system's actual IP address.

Uninstall SurrealDB

To completely remove SurrealDB, remove its container:

docker rm --force surrealdb

Remove SurrealDB image:

docker rmi surrealdb/surrealdb

You can also remove SurrealDB data:

sudo rm -rf /opt/surrealdb

If a user-defined bridge network was created, you can delete it as follows:

docker network rm app-net

Leave a Comment

Cancel reply

Your email address will not be published.