Create a Local Atlas Deployment with Docker
On this page
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.
Create a Local Atlas Deployment with Docker
Install and start Docker.
To learn more, see the Docker documentation.
Connect to the local Atlas deployment.
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:
mongosh "mongodb://localhost:27017/?directConnection=true"
mongosh "mongodb://user:pass@localhost:27017/?directConnection=true"
Create a Local Atlas Deployment with Docker Compose
Create a local Atlas deployment with Docker Compose.
Install and start Docker.
To learn more, see the Docker documentation.
Install Docker Compose.
Example:
brew install docker-compose
To learn more, see the Docker Compose install documentation.
Create a docker-compose.yaml
file.
Create the docker-compose.yaml
file in the same directory
that you run Docker Compose from.
Example:
1 services: 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
Connect to the local Atlas deployment.
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"
Persist Data Across Runs with Docker Compose
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.
Install and start Docker.
To learn more, see the Docker documentation.
Install Docker Compose.
Example:
brew install docker-compose
To learn more, see the Docker Compose install documentation.
Create a docker-compose.yaml
file.
Update the docker-compose.yaml
file to mount the necessary
data directories as volumes.
Example:
1 services: 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 11 volumes: 12 data:
Run Docker Compose.
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
Connect to the local Atlas deployment.
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"
Generate a List of Dependencies
You can generate a list of the dependencies for the
mongodb/mongodb-atlas-local
Docker image.
Install syft.
Example:
brew install syft
To learn more, see the syft README.
Verify the Image Signature
You can verify the signature of the mongodb/mongodb-atlas-local
Docker image.
Install cosign.
Example:
brew install cosign
To learn more, see the cosign Installation.
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'