For AI agents: a documentation index is available at https://www.mongodb.com/docs/llms.txt — markdown versions of all pages are available by appending .md to any URL path.

Create a Local Atlas Deployment with Docker

This tutorial shows you how to create a local Atlas deployment with Docker by using the mongodb/mongodb-atlas-local image. The image deploys a single-node replica set with MongoDB Search and MongoDB Vector Search capabilities.

You can deploy a local Atlas deployment in the following ways:

Method
When to Use It

You want the Atlas CLI to create and manage the container for you.

You want full control over the container configuration without the Atlas CLI.

You want to define the deployment as code, run it alongside other services, or persist data and search indexes across container restarts.

You must pull the image from a private registry instead of Docker Hub.

Required:

  • Docker is installed and running on your local computer.

  • Your computer has at least 2 GB of free RAM and 2 CPU cores.

  • The port you plan to use (default: 27017) is available on localhost.

Recommended:

No virtual private cloud (VPC), firewall, or proxy configuration is required. The deployment runs on local networking.

1

Example:

docker pull mongodb/mongodb-atlas-local:latest

To verify the image signature, see Verify the Local Deployment Image.

2

Example:

docker run -p 27017:27017 mongodb/mongodb-atlas-local
3

Connect to the deployment with mongosh or the connection method that you prefer.

mongosh "mongodb://localhost:27017/?directConnection=true"

Docker Compose defines the deployment as code in a docker-compose.yaml file. Use Docker Compose to run the deployment alongside other services and to persist data, configuration, and search indexes across container restarts.

Note

If you have an existing Docker-Compose based Atlas implementation that you built with the official MongoDB Docker Image and that you'd like to convert to use the Atlas Local Dev image, see Convert to a Local Dev Implementation.

The following complete example creates a local Atlas deployment with persistent data. Create the docker-compose.yaml file in the same directory that you run Docker Compose from.

services: mongodb: image: mongodb/mongodb-atlas-local hostname: mongodb environment: - MONGODB_INITDB_ROOT_USERNAME=user - MONGODB_INITDB_ROOT_PASSWORD=pass ports: - 27017:27017 volumes: - ./init:/docker-entrypoint-initdb.d - db:/data/db - configdb:/data/configdb - mongot:/data/mongotvolumes: db: configdb: mongot:

The services parameter defines the containers to run. The top-level volumes parameter declares the persistent storage locations that the services mount.

Required

The image parameter defines the local MongoDB Atlas image. Without a tag, this definition uses the latest version of the image and is equivalent to using the :latest tag. If your organization requires you to use a specific image build, you can append @sha256:<digest>. If you want to use a specific version of MongoDB with the latest OS updates, use the version number tags. For example, mongodb/mongodb-atlas-local:8.0.6.

Required

The hostname parameter defines the hostname for the container. You must specify this parameter correctly for the local replica set to function. This parameter ensures communication between the different services within the same Docker container network. You can refer to this container by the same hostname, mongodb.

Recommended

The MONGODB_INITDB_ROOT_USERNAME and MONGODB_INITDB_ROOT_PASSWORD environment variables set the initial root username and password for the local Atlas deployment. For simplicity, this example defines the credentials in the Docker Compose file itself, but you can abstract the credentials into environment variables.

Optional

To help diagnose issues, the following environment variables output logs to stderr. mongot, which provides the MongoDB Search capabilities, generates the MONGOT_LOG_FILE. The runner service, which monitors the process that creates mongod and configures the integration with mongot, generates the RUNNER_LOG_FILE.

environment: - MONGOT_LOG_FILE=/dev/stderr - RUNNER_LOG_FILE=/dev/stderr

Volumes persist data and the configuration across container restarts. All volumes are conditional. Mount only the volumes that your deployment requires:

  • ./init:/docker-entrypoint-initdb.d mounts a local init directory to the container's initialization directory. When you run docker compose up, the process runs any .js or .sh initialization scripts in this directory. During the seeding process, the container automatically provides the $CONNECTION_STRING environment variable, so your scripts do not need to build a connection string.

  • db:/data/db persists your data. MongoDB stores its data in the /data/db directory by default.

  • configdb:/data/configdb persists your configuration data. By default, MongoDB stores its configuration data in the /data/configdb directory.

  • mongot:/data/mongot persists your MongoDB Search and MongoDB Vector Search indexes. By default, mongot stores indexes in the /data/mongot directory. Mount this volume to keep search indexes across container restarts.

During initialization, the mongod and mongot processes must start and restart. In some cases the container is running, but the process that you require is not ready. The local MongoDB Atlas image provides a built-in health check that reports when the MongoDB and search processes, and any initialization scripts, are fully ready.

To poll the health check in your scripts, include the following code:

timeout 120 bash -c 'until [ "$(docker inspect --format='\''{{.State.Health.Status}}'\'' <container-name>)" = "healthy" ]; do sleep 2; done'

Replace <container-name> with the container name or ID. For Docker Compose, run docker compose ps -q mongodb to get the container ID.

To start the deployment, run the following command:

docker compose up

Append -d to run the deployment in detached mode.

To stop the deployment, run the following command:

docker compose down

Append -v to remove the volumes and clear the data. Use this option if you do not want to persist data or configuration changes, or to restart from a fresh container.

To verify that the deployment is healthy before you start other services, add the condition: service_healthy parameter to the dependent service:

api: depends_on: mongodb: condition: service_healthy

After starting the deployment, connect to it with mongosh or your application's MongoDB driver:

mongosh "mongodb://user:pass@localhost:27017/?directConnection=true"

If you exposed a different port in your docker-compose.yaml file, replace 27017 with your custom port number. If you did not set authentication environment variables, omit the credentials:

mongosh "mongodb://localhost:27017/?directConnection=true"

You can generate a list of the dependencies for the mongodb/mongodb-atlas-local Docker image.

1

Example:

brew install syft

To learn more, see the syft README.

2
syft mongodb/mongodb-atlas-local

To run the mongodb/mongodb-atlas-local Docker image with GitHub actions, create a workflow file. To learn more, see the GitHub Actions Quickstart.

Example:

Create the following mongodb.yml file in the .github/workflows directory:

on: push: branches: - main pull_request:jobs: run: runs-on: ubuntu-latest services: mongodb: image: mongodb/mongodb-atlas-local ports: - 27017:27017 steps: - name: install mongosh run: | curl --output mongosh.deb https://downloads.mongodb.com/compass/mongodb-mongosh_2.2.1_amd64.deb sudo dpkg -i mongosh.deb mongosh --version - run: mongosh 'mongodb://localhost/?directConnection=true' --eval 'show dbs'

If you have an existing Atlas implementation running in Docker Compose that you have built with the official mongo Docker image, you can refer to the following checklist to simplify converting it to the mongodb-atlas-local image.

  1. Remove any existing command from your docker-compose.yaml file. Because the command in a Docker Compose definition overrides the ENTRYPOINT defined in the mongodb-atlas-local image, you must remove any existing command for the mongodb-atlas-local image to run as designed.

  2. There is no need to define a health check for the Atlas deployment, as this feature is built in to the mongodb-atlas-local image.

The following examples illustrate the likely required changes to your Docker Compose YAML file:

services: self_built_atlas_implementation: image: mongo:8.0 ports: - 27017:27017 command: ["./entrypoint.sh"] # You may have defined a health check for the database in the entrypoint script.
services: local_dev_atlas: image: mongodb/mongodb-atlas-local:8.0 hostname: local_dev_atlas ports: - 27017:27017 environment: - MONGODB_INITDB_ROOT_USERNAME=user - MONGODB_INITDB_ROOT_PASSWORD=pass volumes: - data:/data/db - config:/data/configdb - mongot:/data/mongotvolumes: data: config: mongot:

After starting your container, confirm the deployment is running and that you can connect.

Checkpoint
Verification Step

Image pulled

Run docker images | grep mongodb-atlas-local. The image appears in the output.

Container running

Run docker ps. The container appears with status Up.

Container healthy

Run docker inspect <container-id> | grep Health. The status shows healthy.

Connection succeeds

Connect with mongosh using the connection string (for example, mongodb://localhost:27017/?directConnection=true).

Data volumes present (optional)

Run docker volume ls. The data volumes appear in the output.

After you create and verify your local Atlas deployment with Docker, you can:

  • Connect your application: Use the connection string in your application configuration.

  • Configure data persistence: Map Docker volumes to retain data, configuration, and search indexes across container restarts. See Deploy with Docker Compose for details.

  • Search your data: Use MongoDB Search to create and test search indexes in your local deployment. For detailed steps, see Create a MongoDB Search Index and Run a Query.

  • Use the Atlas CLI instead: For a CLI-managed local deployment, see Create a Local Atlas Deployment.

To discuss local Atlas deployments, see the MongoDB Developer Community forum. To get help, provide feedback, or request features, see the MongoDB Feedback Engine.