bitnami/mongodb

Verified Publisher

By VMware

Updated 4 days ago

Bitnami Secure Image for mongodb

Artifact
Image
Integration & delivery
Internet of things
Databases & storage
266

1B+

bitnami/mongodb repository overview

MongoDB® packaged by Bitnami

What is MongoDB®?

MongoDB® is a relational open source NoSQL database. Easy to use, it stores data in JSON-like documents. Automated scalability and high-performance. Ideal for developing cloud native applications.

Overview of MongoDB® Disclaimer: The respective trademarks mentioned in the offering are owned by the respective companies. We do not provide a commercial license for any of these products. This listing has an open-source license. MongoDB(R) is run and maintained by MongoDB, which is a completely separate project from Bitnami.

TL;DR

docker run --name mongodb bitnami/mongodb:latest

Why use Bitnami Secure Images?

Those are hardened, minimal CVE images built and maintained by Bitnami. Bitnami Secure Images are based on the cloud-optimized, security-hardened enterprise OS Photon Linux. Why choose BSI images?

  • Hardened secure images of popular open source software with Near-Zero Vulnerabilities
  • Vulnerability Triage & Prioritization with VEX Statements, KEV and EPSS Scores
  • Compliance focus with FIPS, STIG, and air-gap options, including secure bill of materials (SBOM)
  • Software supply chain provenance attestation through in-toto
  • First class support for the internet’s favorite Helm charts

Each image comes with valuable security metadata. You can view the metadata in our public catalog here. Note: Some data is only available with commercial subscriptions to BSI.

Alt text Alt text

If you are looking for our previous generation of images based on Debian Linux, please see the Bitnami Legacy registry.

How to deploy MongoDB® in Kubernetes?

Deploying Bitnami applications as Helm Charts is the easiest way to get started with our applications on Kubernetes. Read more about the installation in the Bitnami MongoDB® Chart GitHub repository.

Why use a non-root container?

Non-root container images add an extra layer of security and are generally recommended for production environments. However, because they run as a non-root user, privileged tasks are typically off-limits. Learn more about non-root containers in our docs.

Learn more about the Bitnami tagging policy and the difference between rolling tags and immutable tags in our documentation page.

You can see the equivalence between the different tags by taking a look at the tags-info.yaml file present in the branch folder, i.e bitnami/ASSET/BRANCH/DISTRO/tags-info.yaml.

Subscribe to project updates by watching the bitnami/containers GitHub repo.

Get this image

The recommended way to get the Bitnami MongoDB® Docker Image is to pull the prebuilt image from the Docker Hub Registry.

docker pull bitnami/mongodb:latest

To use a specific version, you can pull a versioned tag. You can view the list of available versions in the Docker Hub Registry.

docker pull bitnami/mongodb:[TAG]

If you wish, you can also build the image yourself by cloning the repository, changing to the directory containing the Dockerfile and executing the docker build command. Remember to replace the APP, VERSION and OPERATING-SYSTEM path placeholders in the example command below with the correct values.

git clone https://github.com/bitnami/containers.git
cd bitnami/APP/VERSION/OPERATING-SYSTEM
docker build -t bitnami/APP:latest .

Persisting your database

If you remove the container all your data will be lost, and the next time you run the image the database will be reinitialized. To avoid this loss of data, you should mount a volume that will persist even after the container is removed.

For persistence you should mount a directory at the /bitnami/mongodb path. If the mounted directory is empty, it will be initialized on the first run.

docker run \
    -v /path/to/mongodb-persistence:/bitnami/mongodb \
    bitnami/mongodb:latest

or by modifying the docker-compose.yml file present in this repository:

 ...
 services:
   mongodb:
     ...
     volumes:
-      - mongodb_data:/bitnami/mongodb
+      - /path/to/mongodb-persistence:/bitnami/mongodb
   ...

NOTE: As this is a non-root container, the mounted files and directories must have the proper permissions for the UID 1001.

Connecting to other containers

Using Docker container networking, a MongoDB® server running inside a container can easily be accessed by your application containers.

Containers attached to the same network can communicate with each other using the container name as the hostname.

Using the Command Line

In this example, we will create a MongoDB® client instance that will connect to the server instance that is running on the same docker network as the client.

Step 1: Create a network
docker network create app-tier --driver bridge
Step 2: Launch the MongoDB® server instance

Use the --network app-tier argument to the docker run command to attach the MongoDB® container to the app-tier network.

docker run -d --name mongodb-server \
    --network app-tier \
    bitnami/mongodb:latest
Step 3: Launch your MongoDB® client instance

Finally we create a new container instance to launch the MongoDB® client and connect to the server created in the previous step:

docker run -it --rm \
    --network app-tier \
    bitnami/mongodb:latest mongo --host mongodb-server
Using a Docker Compose file

When not specified, Docker Compose automatically sets up a new network and attaches all deployed services to that network. However, we will explicitly define a new bridge network named app-tier. In this example we assume that you want to connect to the MongoDB® server from your own custom application image which is identified in the following snippet by the service name myapp.

version: '2'

networks:
  app-tier:
    driver: bridge

services:
  mongodb:
    image: bitnami/mongodb:latest
    networks:
      - app-tier
  myapp:
    image: YOUR_APPLICATION_IMAGE
    networks:
      - app-tier

IMPORTANT:

  1. Please update the YOUR_APPLICATION_IMAGE_ placeholder in the above snippet with your application image
  2. In your application container, use the hostname mongodb to connect to the MongoDB® server

Launch the containers using:

docker-compose up -d

Configuration

Environment variables
Customizable environment variables
NameDescriptionDefault Value
MONGODB_MOUNTED_CONF_DIRDirectory for including custom configuration files (that override the default generated ones)${MONGODB_VOLUME_DIR}/conf
MONGODB_INIT_RETRY_ATTEMPTSMaximum retries for checking the service initialization status7
MONGODB_INIT_RETRY_DELAYTime (in seconds) to wait between retries for checking the service initialization status5
MONGODB_PORT_NUMBERMongoDB port$MONGODB_DEFAULT_PORT_NUMBER
MONGODB_EXTRA_FLAGSExtra flags for MongoDB initializationnil
MONGODB_ENABLE_NUMACTLExecute commands using numactlfalse
MONGODB_SHELL_EXTRA_FLAGSExtra flags when using the mongodb client during initialization (useful when mounting init scripts)nil
MONGODB_ADVERTISED_HOSTNAMEHostname to use for advertising the MongoDB servicenil
MONGODB_ADVERTISE_IPWhether advertised hostname is set to container ipfalse
MONGODB_ADVERTISED_PORT_NUMBERMongoDB advertised port number. It is recommended to pass this environment variable if you have a proxy port forwarding requests to container.nil
MONGODB_DISABLE_JAVASCRIPTDisable MongoDB server-side javascript executionno
MONGODB_ENABLE_JOURNALEnable MongoDB journalnil
MONGODB_DISABLE_SYSTEM_LOGDisable MongoDB daemon system lognil
MONGODB_ENABLE_DIRECTORY_PER_DBUse a separate folder for storing each database datanil
MONGODB_ENABLE_IPV6Use IPv6 for database connectionsnil
MONGODB_SYSTEM_LOG_VERBOSITYMongoDB daemon log levelnil
MONGODB_ROOT_USERUser name for the MongoDB root userroot
MONGODB_ROOT_PASSWORDPassword for the MongoDB root usernil
MONGODB_USERNAMEUser to generate at initialization timenil
MONGODB_PASSWORDPassword for the non-root user specified in MONGODB_USERNAMEnil
MONGODB_DATABASEName of the database to create at initialization timenil
MONGODB_METRICS_USERNAMEUser used for metrics collection, for example with mongodb_exporternil
MONGODB_METRICS_PASSWORDPassword for the non-root user specified in MONGODB_METRICS_USERNAMEnil
MONGODB_EXTRA_USERNAMESComma or semicolon separated list of extra users to be created.nil
MONGODB_EXTRA_PASSWORDSComma or semicolon separated list of passwords for the users specified in MONGODB_EXTRA_USERNAMES.nil
MONGODB_EXTRA_DATABASESComma or semicolon separated list of databases to create at initialization time for the users specified in MONGODB_EXTRA_USERNAMES.nil
ALLOW_EMPTY_PASSWORDPermit accessing MongoDB without setting any passwordno
MONGODB_REPLICA_SET_MODEMongoDB replica set mode. Can be one of primary, secondary or arbiternil
MONGODB_REPLICA_SET_NAMEName of the MongoDB replica set$MONGODB_DEFAULT_REPLICA_SET_NAME
MONGODB_REPLICA_SET_KEYMongoDB replica set keynil
MONGODB_INITIAL_PRIMARY_HOSTHostname of the replica set primary node (necessary for arbiter and secondary nodes)nil
MONGODB_INITIAL_PRIMARY_PORT_NUMBERPort of the replica set primary node (necessary for arbiter and secondary nodes)27017
MONGODB_INITIAL_PRIMARY_ROOT_PASSWORDPrimary node root user password (necessary for arbiter and secondary nodes)nil
MONGODB_INITIAL_PRIMARY_ROOT_USERPrimary node root username (necessary for arbiter and secondary nodes)root
MONGODB_SET_SECONDARY_OKMark node as readable. Necessary for cases where the PVC is lostno
MONGODB_DISABLE_ENFORCE_AUTHBy default, MongoDB authentication will be enforced. If set to true, MongoDB will not enforce authenticationfalse
Read-only environment variables
NameDescriptionValue
MONGODB_VOLUME_DIRPersistence base directory$BITNAMI_VOLUME_DIR/mongodb
MONGODB_BASE_DIRMongoDB installation directory$BITNAMI_ROOT_DIR/mongodb
MONGODB_CONF_DIRMongoDB configuration directory$MONGODB_BASE_DIR/conf
MONGODB_DEFAULT_CONF_DIRMongoDB default configuration directory$MONGODB_BASE_DIR/conf.default
MONGODB_LOG_DIRMongoDB logs directory$MONGODB_BASE_DIR/logs
MONGODB_DATA_DIRMongoDB data directory${MONGODB_VOLUME_DIR}/data
MONGODB_TMP_DIRMongoDB temporary directory$MONGODB_BASE_DIR/tmp
MONGODB_BIN_DIRMongoDB executables directory$MONGODB_BASE_DIR/bin
MONGODB_TEMPLATES_DIRDirectory where the mongodb.conf template file is stored$MONGODB_BASE_DIR/templates
MONGODB_MONGOD_TEMPLATES_FILEPath to the mongodb.conf template file$MONGODB_TEMPLATES_DIR/mongodb.conf.tpl
MONGODB_CONF_FILEPath to MongoDB configuration file$MONGODB_CONF_DIR/mongodb.conf
MONGODB_KEY_FILEPath to the MongoDB replica set keyfile$MONGODB_CONF_DIR/keyfile
MONGODB_DB_SHELL_FILEPath to MongoDB dbshell file/.dbshell
MONGODB_RC_FILEPath to MongoDB rc file/.mongorc.js
MONGOSH_DIRPath to mongosh directory/.mongodb
MONGOSH_RC_FILEPath to mongosh rc file/.mongoshrc.js
MONGODB_PID_FILEPath to the MongoDB PID file$MONGODB_TMP_DIR/mongodb.pid
MONGODB_LOG_FILEPath to the MongoDB log file$MONGODB_LOG_DIR/mongodb.log
MONGODB_INITSCRIPTS_DIRPath to the MongoDB container init scripts directory/docker-entrypoint-initdb.d
MONGODB_DAEMON_USERMongoDB system usermongo
MONGODB_DAEMON_GROUPMongoDB system groupmongo
MONGODB_DEFAULT_PORT_NUMBERMongoDB port set at build time27017
MONGODB_DEFAULT_ENABLE_JOURNALEnable MongoDB journal at build timetrue
MONGODB_DEFAULT_DISABLE_SYSTEM_LOGDisable MongoDB daemon system log set at build timefalse
MONGODB_DEFAULT_ENABLE_DIRECTORY_PER_DBUse a separate folder for storing each database data set at build timefalse
MONGODB_DEFAULT_ENABLE_IPV6Use IPv6 for database connections set at build timefalse
MONGODB_DEFAULT_SYSTEM_LOG_VERBOSITYMongoDB daemon log level set at build time0
MONGODB_DEFAULT_REPLICA_SET_NAMEName of the MongoDB replica set at build timereplicaset
Initializing a new instance

When the container is executed for the first time, it will execute the files with extensions .sh, and .js located at /docker-entrypoint-initdb.d.

In order to have your custom files inside the docker image you can mount them as a volume.

Passing extra command-line flags to mongod startup

Passing extra command-line flags to the mongod service command is possible through the following env var:

  • MONGODB_EXTRA_FLAGS: Flags to be appended to the mongod startup command. No defaults
  • MONGODB_CLIENT_EXTRA_FLAGS: Flags to be appended to the mongo command which is used to connect to the (local or remote) mongod daemon. No defaults
docker run --name mongodb -e ALLOW_EMPTY_PASSWORD=yes -e MONGODB_EXTRA_FLAGS='--wiredTigerCacheSizeGB=2' bitnami/mongodb:latest

or by modifying the docker-compose.yml file present in this repository:

services:
  mongodb:
  ...
    environment:
      - ALLOW_EMPTY_PASSWORD=yes
      - MONGODB_EXTRA_FLAGS=--wiredTigerCacheSizeGB=2
  ...
Configuring system log verbosity level

Configuring the system log verbosity level is possible through the following env vars:

  • MONGODB_DISABLE_SYSTEM_LOG: Whether to enable/disable system log on MongoDB®. Default: false. Possible values: [true, false].
  • MONGODB_SYSTEM_LOG_VERBOSITY: MongoDB® system log verbosity level. Default: 0. Possible values: [0, 1, 2, 3, 4, 5]. For more information about the verbosity levels please refer to the MongoDB® documentation
docker run --name mongodb -e ALLOW_EMPTY_PASSWORD=yes -e MONGODB_SYSTEM_LOG_VERBOSITY='3' bitnami/mongodb:latest

or by modifying the docker-compose.yml file present in this repository:

services:
  mongodb:
  ...
    environment:
      - ALLOW_EMPTY_PASSWORD=yes
      - MONGODB_SYSTEM_LOG_VERBOSITY=3
  ...
Using numactl

In order to enable launching commands using numactl, set the MONGODB_ENABLE_NUMACTL variable to true. For more information on this, check the official [MongoDB documentation][(https://docs.mongodb.com/manual/administration/production-notes/#configuring-numa-on-linux)

Enabling/disabling IPv6

Enabling/disabling IPv6 is possible through the following env var:

  • MONGODB_ENABLE_IPV6: Whether to enable/disable IPv6 on MongoDB®. Default: false. Possible values: [true, false]

To enable IPv6 support, you can execute:

docker run --name mongodb -e ALLOW_EMPTY_PASSWORD=yes -e MONGODB_ENABLE_IPV6=yes bitnami/mongodb:latest

or by modifying the docker-compose.yml file present in this repository:

services:
  mongodb:
  ...
    environment:
      - ALLOW_EMPTY_PASSWORD=yes
      - MONGODB_ENABLE_IPV6=yes
  ...
Enabling/disabling directoryPerDB

Enabling/disabling directoryPerDB is possible through the following env var:

  • MONGODB_ENABLE_DIRECTORY_PER_DB: Whether to enable/disable directoryPerDB on MongoDB®. Default: true. Possible values: [true, false]
docker run --name mongodb -e ALLOW_EMPTY_PASSWORD=yes -e MONGODB_ENABLE_DIRECTORY_PER_DB=yes bitnami/mongodb:latest

or by mo

Note: the README for this container is longer than the DockerHub length limit of 25000, so it has been trimmed. The full README can be found at https://github.com/bitnami/containers/blob/main/bitnami/mongodb/README.md

Tag summary

Content type

Image

Digest

sha256:6b1e67f1b

Size

7.8 kB

Last updated

4 days ago

Requires Docker Desktop 4.37.1 or later.

This week's pulls

Pulls:

39,534

Last week

Bitnami