Skip to content

Deploy MongoDB

This guide shows you how to use MongoDB, a source-available, cross-platform, document-oriented database program.

To run it, follow these steps:

  1. Install the kraft CLI tool and a container runtime engine, e.g. Docker.

  2. Clone the examples repository and cd into the examples/mongodb/ directory:

Terminal window
git clone
cd examples/mongodb/

Make sure to log into KraftCloud by setting your token and a metro close to you. We use fra0 (Frankfurt, πŸ‡©πŸ‡ͺ) in this guide:

Terminal window
# Set KraftCloud access token
# Set metro to Frankfurt, DE

When done, invoke the following command to deploy this application on KraftCloud:

Terminal window
kraft cloud deploy -p 27017:27017/tls -M 1024 .

The output shows the instance URL and other details:

Terminal window
[●] Deployed successfully!
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ name: mongodb-6tiuu
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ uuid: 99779597-0bdb-4160-b902-a160c3ab4b2a
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€ state: running
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ fqdn:
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€ image: mongodb@sha256:e6ff5153f106e2d5e2a10881818cd1b90fe3ff1294ad80879b2239ffc52aff0e
β”œβ”€β”€β”€β”€β”€ boot time: 82.41 ms
β”œβ”€β”€β”€β”€β”€β”€β”€β”€ memory: 1024 MiB
β”œβ”€ service group: bold-brook-khkwv7of
β”œβ”€β”€ private fqdn: mongodb-6tiuu.internal
β”œβ”€β”€β”€β”€ private ip:
└────────── args: /usr/bin/mongod --bind_ip_all --nounixsocket

In this case, the instance name is mongodb-6tiuu and the service name is bold-brook-khkwv7of. They are different for each run.

To test the deployment, first forward the port with the kraft cloud tunnel command. Be sure to use the service group returned by the kraft cloud deploy command:

Terminal window
kraft cloud tunnel bold-brook-khkwv7of 27017:27017

Then, on a separate console, you can use the mongosh client to connect to the server:

Terminal window
mongosh mongodb://localhost

You should see output similar to:

Terminal window
Current Mongosh Log ID: 65d75b96310f70e63565e0f1
Connecting to: mongodb://localhost/?directConnection=true&serverSelectionTimeoutMS=2000&appName=mongosh+2.1.5
(node:79750) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
Using MongoDB: 6.0.13
Using Mongosh: 2.1.5
For mongosh info see:
To help improve our products, anonymous usage data is collected and sent to MongoDB periodically (
You can opt-out by running the disableTelemetry() command.

To disconnect, simply kill the tunnel command with ctrl-C

At any point in time, you can list information about the instance:

Terminal window
kraft cloud instance list
mongodb-6tiuu bold-brook-khkwv7of.fra0.kraft... running 20 minutes ago mongodb@sha256:e6ff5153f106e2... 1.0 GiB /usr/bin/mongod --bind_ip_all... 82410us

When done, you can remove the instance:

Terminal window
kraft cloud instance remove mongodb-6tiuu

Customize your Application

To customize the application, update the files in the repository, listed below:

  • Kraftfile: the KraftCloud specification, including command-line arguments
  • Dockerfile: In case you need to add files to your instance’s rootfs
spec: v0.6
runtime: mongo:latest
rootfs: ./Dockerfile
cmd: ["/usr/bin/mongod", "--bind_ip_all", "--nounixsocket"]

Learn More

Use the --help option for detailed information on using KraftCloud:

Terminal window
kraft cloud --help

Or visit the CLI Reference.