Docs Menu
Docs Home
/ /
Atlas CLI
/ /

Create a Local Atlas Deployment with Docker

On this page

  • Create a Local Atlas Deployment with Docker
  • Create a Local Atlas Deployment with Docker Compose
  • Persist Data Across Runs with Docker Compose
  • Generate a List of Dependencies
  • Verify the Image Signature
  • Run the Image with GitHub Actions

This tutorial shows you how to create a local Atlas deployment with Docker. In this tutorial, we will deploy a single-node replica set with Docker.

Important

Public Preview

Local deployments in Docker and Docker Compose are available as a Public Preview. The feature and corresponding documentation may change at any time in the Public Preview stage. To ask questions and provide feedback, see the Atlas CLI Local Development Community Forum.

1

To learn more, see the Docker documentation.

2

Example:

docker pull mongodb/mongodb-atlas-local:latest
3

Example:

The logs display as the Docker image runs.

4

To connect to the local Atlas deployment from the host (not container), copy and paste the following command into a new terminal, and replace the {connection_string} variable with your connection string.

Note

The following example uses mongosh, but you can use the connection method that you prefer.

mongosh {connection_string}

Examples:

Create a local Atlas deployment with Docker Compose.

1

To learn more, see the Docker documentation.

2

Example:

brew install docker-compose

To learn more, see the Docker Compose install documentation.

3

Create the docker-compose.yaml file in the same directory that you run Docker Compose from.

Example:

1services:
2 mongodb:
3 image: mongodb/mongodb-atlas-local
4 environment:
5 - MONGODB_INITDB_ROOT_USERNAME=user
6 - MONGODB_INITDB_ROOT_PASSWORD=pass
7 ports:
8 - 27018:27017
4

The following command creates a local Atlas deployment with Atlas Search capabilities enabled.

Example:

docker-compose up
5

To connect to the local Atlas deployment from the host (not container), copy and paste the following command into a new terminal, and replace the {connection_string} variable with your connection string.

Note

The following example uses mongosh, but you can use the connection method that you prefer.

mongosh {connection_string}

Example:

mongosh "mongodb://user:pass@localhost:27018/?directConnection=true"
6
docker compose down -v

You can persist data across multiple runs with Docker Compose. Persisting data helps to ensure that data isn't lost between runs. Data remains available across runs of Docker Compose.

1

To learn more, see the Docker documentation.

2

Example:

brew install docker-compose

To learn more, see the Docker Compose install documentation.

3

Update the docker-compose.yaml file to mount the necessary data directories as volumes.

Example:

1services:
2 mongodb:
3 image: mongodb/mongodb-atlas-local
4 environment:
5 - MONGODB_INITDB_ROOT_USERNAME=user
6 - MONGODB_INITDB_ROOT_PASSWORD=pass
7 ports:
8 - 27019:27017
9 volumes:
10 - data:/data/db
11volumes:
12 data:
4

The following command creates a local Atlas deployment with Atlas Search capabilities enabled.

Example:

docker-compose up

You can also run Docker Compose in detached mode.

Example:

docker-compose up -d
5

To connect to the local Atlas deployment from the host (not container), copy and paste the following command into a new terminal, and replace the {connection_string} variable with your connection string.

Note

The following example uses mongosh, but you can use the connection method that you prefer.

mongosh {connection_string}

Example:

mongosh "mongodb://user:pass@localhost:27019/?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

You can verify the signature of the mongodb/mongodb-atlas-local Docker image.

1

Example:

brew install cosign

To learn more, see the cosign Installation.

2

Example:

curl -O https://cosign.mongodb.com/mongodb-atlas-local.pem
COSIGN_REPOSITORY="docker.io/mongodb/signatures" cosign verify --private-infrastructure --key=./mongodb-atlas-local.pem "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'
← Create a Local Deployment