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.
Choose a Deployment Method
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. |
Before You Begin
Required:
Docker is installed and running on your local computer.
For macOS or Windows, install Docker Desktop v4.31 or later.
For Linux, install Docker Engine v27.0 or later.
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:
Install mongosh version 2.0 or later to connect to and interact with the deployment.
For Docker Compose workflows, install Docker Compose v2 or later.
No virtual private cloud (VPC), firewall, or proxy configuration is required. The deployment runs on local networking.
Deploy with docker run
Pull down the mongodb/mongodb-atlas-local Docker image.
Example:
docker pull mongodb/mongodb-atlas-local:latestTo verify the image signature, see Verify the Local Deployment Image.
Connect to the local Atlas deployment.
Connect to the deployment with mongosh or the connection method that you prefer.
mongosh "mongodb://localhost:27017/?directConnection=true"mongosh "mongodb://user:pass@localhost:27017/?directConnection=true"Deploy with Docker Compose
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.
Docker Compose File
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.
Image
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.
Hostname
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.
Environment
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/stderrVolumes
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.dmounts a localinitdirectory to the container's initialization directory. When you rundocker compose up, the process runs any.jsor.shinitialization scripts in this directory. During the seeding process, the container automatically provides the$CONNECTION_STRINGenvironment variable, so your scripts do not need to build a connection string.db:/data/dbpersists your data. MongoDB stores its data in the/data/dbdirectory by default.configdb:/data/configdbpersists your configuration data. By default, MongoDB stores its configuration data in the/data/configdbdirectory.mongot:/data/mongotpersists your MongoDB Search and MongoDB Vector Search indexes. By default,mongotstores indexes in the/data/mongotdirectory. Mount this volume to keep search indexes across container restarts.
Verify Process Health
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.
Start and Stop the Deployment
To start the deployment, run the following command:
docker compose upAppend -d to run the deployment in detached mode.
To stop the deployment, run the following command:
docker compose downAppend -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_healthyConnect to the Deployment
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"Generate a List of Dependencies
You can generate a list of the dependencies for the mongodb/mongodb-atlas-local Docker image.
Run the Image with GitHub Actions
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'Convert Official Image to a Local Atlas Deployment
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.
Remove any existing
commandfrom yourdocker-compose.yamlfile. Because thecommandin a Docker Compose definition overrides theENTRYPOINTdefined in themongodb-atlas-localimage, you must remove any existingcommandfor themongodb-atlas-localimage to run as designed.There is no need to define a health check for the Atlas deployment, as this feature is built in to the
mongodb-atlas-localimage.
Example Docker Compose Updates
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:Verify the Deployment
After starting your container, confirm the deployment is running and that you can connect.
Checkpoint | Verification Step |
|---|---|
Image pulled | Run |
Container running | Run |
Container healthy | Run |
Connection succeeds | Connect with |
Data volumes present (optional) | Run |
Next Steps
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.
Feedback
To discuss local Atlas deployments, see the MongoDB Developer Community forum. To get help, provide feedback, or request features, see the MongoDB Feedback Engine.