Docs Menu

Docs HomeDevelop ApplicationsMongoDB Manual

Install MongoDB Community with Docker

On this page

  • About This Task
  • Before You Begin
  • Procedure
  • Next Steps (Optional)

You can run MongoDB community Edition as a Docker container using the official MongoDB Community image. Using a Docker image for running your MongoDB deployment is useful to:

  • Stand up a deployment quickly.

  • Help manage configuration files.

  • Test different features on multiple versions of MongoDB.

This page describes the Docker install instructions for MongoDB Community edition. The MongoDB Enterprise Docker image in conjunction with the MongoDB Kubernetes Operator are recommended for production deployments. For enterprise instructions, see Install MongoDB Enterprise with Docker.

This procedure uses the official mongo community image, which is maintained by MongoDB.

A full description of Docker is beyond the scope of this documentation. This page assumes prior knowledge of Docker.

Before you can run a MongoDB Community Docker container, you must install Docker .

1
docker pull mongodb/mongodb-community-server
2
docker run --name mongo -d mongodb/mongodb-community-server:latest

Note

Install a Specific Version of MongoDB

To install a specific version of MongoDB, specify the version after the : in the Docker run command. Docker pulls and runs the specified version.

For example, to run MongoDB 5.0:

docker run --name mongo -d mongodb/mongodb-community-server:5.0-ubi8

For a full list of available MongoDB Community Server images, see: the official Docker Hub page.

3

To check the status of your Docker container, run the following command:

docker container ls

The output from the ls command lists the following fields that describe the running container:

  • Container ID

  • Image

  • Command

  • Created

  • Status

  • Port

  • Names

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c29db5687290 mongodb/mongodb-community-server:5.0-ubi8 "docker-entrypoint.s…" 4 seconds ago Up 3 seconds 27017/tcp mongo
4

Open an interactive container instance of mongo and connect to the deployment with mongosh.

docker exec -it mongo mongosh
5

To confirm your MongoDB instance is running, run the Hello command:

db.runCommand(
{
hello: 1
}
)

The result of this command returns a document describing your mongod deployment:

{
isWritablePrimary: true,
topologyVersion: {
processId: ObjectId("63c00e27195285e827d48908"),
counter: Long("0")
},
maxBsonObjectSize: 16777216,
maxMessageSizeBytes: 48000000,
maxWriteBatchSize: 100000,
localTime: ISODate("2023-01-12T16:51:10.132Z"),
logicalSessionTimeoutMinutes: 30,
connectionId: 18,
minWireVersion: 0,
maxWireVersion: 20,
readOnly: false,
ok: 1
}

You can use Cosign to verify MongoDB's signature for container images.

This procedure is optional. You do not need to verify MongoDB's signature to run MongoDB on Docker or any other containerized platform.

To verify MongoDB's container signature, perform the following steps:

1

For installation instructions, see the Cosign GitHub repository.

2
curl https://cosign.mongodb.com/server.pem > server.pem
3

Run the following command to verify the signature by tag:

COSIGN_REPOSITORY=docker.io/mongodb/signatures cosign verify --private-infrastructure --key=./server.pem docker.io/mongodb/mongodb-community-server:latest
← Install MongoDB Community on Windows using msiexec.exe