Back to Surrealdb

DOCKER

docker/DOCKER.md

3.0.511.1 KB
Original Source
<p align="center"> <a href="https://surrealdb.com" target="_blank">
</a>
</p> <p align="center"> <a href="https://github.com/surrealdb/surrealdb"></a> &nbsp; <a href="https://github.com/surrealdb/surrealdb"></a> &nbsp; <a href="https://github.com/surrealdb/surrealdb/actions"></a> &nbsp; <a href="https://status.surrealdb.com"></a> &nbsp; <a href="https://hub.docker.com/repository/docker/surrealdb/surrealdb"></a> &nbsp; <a href="https://github.com/surrealdb/license"></a> </p> <p align="center"> <a href="https://surrealdb.com/discord"></a> &nbsp; <a href="https://x.com/surrealdb"></a> &nbsp; <a href="https://dev.to/surrealdb"></a> &nbsp; <a href="https://www.linkedin.com/company/surrealdb/"></a> </p> <p align="center"> <a href="https://surrealdb.com/blog"></a> &nbsp; <a href="https://github.com/surrealdb/surrealdb"></a> &nbsp; <a href="https://www.linkedin.com/company/surrealdb/"></a> &nbsp; <a href="https://x.com/surrealdb"></a> &nbsp; <a href="https://www.youtube.com/@surrealdb"></a> &nbsp; <a href="https://dev.to/surrealdb"></a> &nbsp; <a href="https://surrealdb.com/discord"></a> &nbsp; <a href="https://stackoverflow.com/questions/tagged/surrealdb"></a> </p> <h2>&nbsp;&nbsp;What is SurrealDB?</h2>

SurrealDB is an end-to-end cloud native database for web, mobile, serverless, jamstack, backend, and traditional applications. SurrealDB reduces the development time of modern applications by simplifying your database and API stack, removing the need for most server-side components, allowing you to build secure, performant apps quicker and cheaper. SurrealDB acts as both a database and a modern, realtime, collaborative API backend layer. SurrealDB can run as a single server or in a highly-available, highly-scalable distributed mode - with support for SQL querying from client devices, GraphQL, ACID transactions, WebSocket connections, structured and unstructured data, graph querying, full-text indexing, geospatial querying, and row-by-row permissions-based access.

View the features, the latest releases, the product roadmap, and documentation.

<h2>&nbsp;&nbsp;Documentation</h2>

For guidance on installation, development, deployment, and administration, see our documentation.

<h2>&nbsp;&nbsp;Run using Docker</h2>

Docker can be used to manage and run SurrealDB database instances without the need to install any command-line tools. The SurrealDB docker container contains the full command-line tools for importing and exporting data from a running server, or for running a server itself.

For just getting started with a development server running in memory, you can start the container with basic initialization arguments to create a root user with "root" as username and password and enable debug logging.

bash
docker run --rm --pull always --name surrealdb -p 8000:8000 surrealdb/surrealdb:latest start --log debug --user root --pass root memory

You can access the server using the same SurrealDB CLI provided in the image by using the sql command:

bash
docker exec -it <container_name> /surreal sql -e http://localhost:8000 -u root -p root --ns test --db test --pretty
<h2>&nbsp;&nbsp;Run using Docker Compose</h2>

The Docker image can be used with the docker compose command.

Here is an example of a basic docker-compose.yml file for quickly getting started.

yaml
services:
  surrealdb:
    command: start 
    image: surrealdb/surrealdb:latest # Consider using a specific version
    pull_policy: always
    ports:
      - 8000:8000
    environment:
      - SURREAL_LOG=info # Use "info" in production
      - SURREAL_USER=root
      - SURREAL_PASS=root # Change this in production!

Most of the configuration of SurrealDB can be done through environment variables.

You can find a comprehensive list of all the available environment variables in the help message of the start subcommand:

shell
docker run --rm surrealdb/surrealdb:latest start --help

The image contains timezone data. Specify the required timezone with the TZ environment variable:

bash
docker run -e TZ=Europe/London surrealdb/surrealdb:latest start

SurrealDB can be executed as a non-root user for added security. This ensures that exploiting certain vulnerabilities in the SurrealDB process does not immediately result in privileged access to the container. When doing this, ensure that any files required by SurrealDB are mounted to the container in a volume and that are accessible to that non-root user through their ownership and permissions.

Here is an example of running the container with a persistent volume as a non-root user with Docker Compose:

yaml
services:
  surrealdb:
    image: surrealdb/surrealdb:latest # Consider using a specific version
    pull_policy: always
    command: start rocksdb:/mydata/mydatabase.db
    user: "1000"
    ports:
      - 8000:8000
    volumes:
      - ./mydata:/mydata
    environment:
      - SURREAL_LOG=debug # Use "info" in production
      - SURREAL_USER=root
      - SURREAL_PASS=root # Change this in production!

In this example, you should ensure that the user with UID 1000 exists in the host and that it has access (e.g. ownership) to read and write in the ./mydata directory. You can find the UID of the active user in the host by running id -u. You can also provide a group for the container process to run as, such as for example user: "1000:1000".

The same behavior can be acomplished without Docker Compose by providing the -u or --user argument to docker run. Similar mechanisms exist in other container management tools such as Podman or container orchestration systems such as Kubernetes.

<h2>&nbsp;&nbsp;Community</h2>

Join our growing community around the world, for help, ideas, and discussions regarding SurrealDB.

<h2>&nbsp;&nbsp;Contributing</h2>

We would    for you to get involved with SurrealDB development! If you wish to help, you can learn more about how you can contribute to this project in the contribution guide.

<h2>&nbsp;&nbsp;Security</h2>

For security issues, view our vulnerability policy, view our security policy, and kindly email us at [email protected] instead of posting a public issue on GitHub.

<h2>&nbsp;&nbsp;License</h2>

Source code for SurrealDB is variously licensed under a number of different licenses. A copy of each license can be found in each repository.

For more information, see the licensing information.