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.
Docs Menu

Install MongoDB Community on Docker

You can run MongoDB Community Edition as a Docker container using the official MongoDB Community image. This page describes how to install, run, verify, and connect to MongoDB Community Edition in Docker.

Before you install MongoDB Community Edition on Docker, complete the following prerequisites:

  • Install Docker on your host.

  • Install mongosh.

  • Confirm that your host platform is supported. To learn which platforms MongoDB runs on, see Platform Support.

  • MongoDB 5.0+ Docker images require AVX support on your system. If your system does not support AVX, you can use a docker image of MongoDB prior to version 5.0.

    Warning

    Versions of MongoDB prior to 7.0 are EOL'd and no longer supported by MongoDB. These versions should be used for testing purposes only.

To pull the MongoDB 9.0 Community Server image, run the following command:

docker pull mongodb/mongodb-community-server:9.0-ubi9-slim
1

Run the following command to start a container named mongodb from the image:

docker run --name mongodb -p 27017:27017 -d mongodb/mongodb-community-server:9.0-ubi9-slim

The -d flag runs the container in the background. The -p 27017:27017 flag publishes the container port to the host port.

You can append mongod command-line options to the docker run command. For example, to start a single-node replica set instead, run the following command:

docker run --name mongodb -p 27017:27017 -d mongodb/mongodb-community-server:9.0-ubi9-slim --replSet myReplicaSet
2

To list running containers, run docker ps. The output includes the container ID, image, status, and published ports:

docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c29db5687290 mongodb/mongodb-community-server:9.0-ubi9-slim "docker-entrypoint.s…" 4 seconds ago Up 3 seconds 0.0.0.0:27017->27017/tcp mongodb
1

To connect to your deployment, run mongosh:

mongosh

Because the docker run command publishes the container port to the host, mongosh connects to the default address, localhost:27017.

2

To report the status of your MongoDB instance, run the serverStatus command:

db.runCommand( { serverStatus: 1 } )

The command returns a document that describes your mongod deployment.

Earn a Skill Badge

Master "MongoDB Architecture Essentials" for free!

Learn more

Rate this page