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 Images?
- Bitnami closely tracks upstream source changes and promptly publishes new versions of this image using our automated systems.
- With Bitnami images the latest bug fixes and features are available as soon as possible.
- Bitnami containers, virtual machines and cloud images use the same components and configuration approach - making it easy to switch between formats based on your project needs.
- All our images are based on minideb -a minimalist Debian based container image that gives you a small base container image and the familiarity of a leading Linux distribution- or scratch -an explicitly empty image-.
- All Bitnami images available in Docker Hub are signed with Notation. Check this post to know how to verify the integrity of the images.
- Bitnami container images are released on a regular basis with the latest distribution packages available.
Looking to use MongoDB® in production? Try VMware Tanzu Application Catalog, the commercial edition of the Bitnami catalog.
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.
Bitnami containers can be used with Kubeapps for deployment and management of Helm Charts in clusters.
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.
Only latest stable branch maintained in the free Bitnami catalog
Starting December 10th 2024, only the latest stable branch of any container will receive updates in the free Bitnami catalog. To access up-to-date releases for all upstream-supported branches, consider upgrading to Bitnami Premium. Previous versions already released will not be deleted. They are still available to pull from DockerHub.
Please check the Bitnami Premium page in our partner Arrow Electronics for more information.
Supported tags and respective Dockerfile
links
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:
- Please update the YOUR_APPLICATION_IMAGE_ placeholder in the above snippet with your application image
- 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
Name | Description | Default Value |
---|---|---|
MONGODB_MOUNTED_CONF_DIR |
Directory for including custom configuration files (that override the default generated ones) | ${MONGODB_VOLUME_DIR}/conf |
MONGODB_INIT_RETRY_ATTEMPTS |
Maximum retries for checking the service initialization status | 7 |
MONGODB_INIT_RETRY_DELAY |
Time (in seconds) to wait between retries for checking the service initialization status | 5 |
MONGODB_PORT_NUMBER |
MongoDB port | $MONGODB_DEFAULT_PORT_NUMBER |
MONGODB_ENABLE_MAJORITY_READ |
Enable majority read in MongoDB operations | true |
MONGODB_DEFAULT_ENABLE_MAJORITY_READ |
Enable majority read in MongoDB operations set at build time | true |
MONGODB_EXTRA_FLAGS |
Extra flags for MongoDB initialization | nil |
MONGODB_ENABLE_NUMACTL |
Execute commands using numactl | false |
MONGODB_SHELL_EXTRA_FLAGS |
Extra flags when using the mongodb client during initialization (useful when mounting init scripts) | nil |
MONGODB_ADVERTISED_HOSTNAME |
Hostname to use for advertising the MongoDB service | nil |
MONGODB_ADVERTISE_IP |
Whether advertised hostname is set to container ip | false |
MONGODB_ADVERTISED_PORT_NUMBER |
MongoDB advertised port number. It is recommended to pass this environment variable if you have a proxy port forwarding requests to container. | nil |
MONGODB_DISABLE_JAVASCRIPT |
Disable MongoDB server-side javascript execution | no |
MONGODB_ENABLE_JOURNAL |
Enable MongoDB journal | nil |
MONGODB_DISABLE_SYSTEM_LOG |
Disable MongoDB daemon system log | nil |
MONGODB_ENABLE_DIRECTORY_PER_DB |
Use a separate folder for storing each database data | nil |
MONGODB_ENABLE_IPV6 |
Use IPv6 for database connections | nil |
MONGODB_SYSTEM_LOG_VERBOSITY |
MongoDB daemon log level | nil |
MONGODB_ROOT_USER |
User name for the MongoDB root user | root |
MONGODB_ROOT_PASSWORD |
Password for the MongoDB root user | nil |
MONGODB_USERNAME |
User to generate at initialization time | nil |
MONGODB_PASSWORD |
Password for the non-root user specified in MONGODB_USERNAME | nil |
MONGODB_DATABASE |
Name of the database to create at initialization time | nil |
MONGODB_METRICS_USERNAME |
User used for metrics collection, for example with mongodb_exporter | nil |
MONGODB_METRICS_PASSWORD |
Password for the non-root user specified in MONGODB_METRICS_USERNAME | nil |
MONGODB_EXTRA_USERNAMES |
Comma or semicolon separated list of extra users to be created. | nil |
MONGODB_EXTRA_PASSWORDS |
Comma or semicolon separated list of passwords for the users specified in MONGODB_EXTRA_USERNAMES. | nil |
MONGODB_EXTRA_DATABASES |
Comma or semicolon separated list of databases to create at initialization time for the users specified in MONGODB_EXTRA_USERNAMES. | nil |
ALLOW_EMPTY_PASSWORD |
Permit accessing MongoDB without setting any password | no |
MONGODB_REPLICA_SET_MODE |
MongoDB replica set mode. Can be one of primary, secondary or arbiter | nil |
MONGODB_REPLICA_SET_NAME |
Name of the MongoDB replica set | $MONGODB_DEFAULT_REPLICA_SET_NAME |
MONGODB_REPLICA_SET_KEY |
MongoDB replica set key | nil |
MONGODB_INITIAL_PRIMARY_HOST |
Hostname of the replica set primary node (necessary for arbiter and secondary nodes) | nil |
MONGODB_INITIAL_PRIMARY_PORT_NUMBER |
Port of the replica set primary node (necessary for arbiter and secondary nodes) | 27017 |
MONGODB_INITIAL_PRIMARY_ROOT_PASSWORD |
Primary node root user password (necessary for arbiter and secondary nodes) | nil |
MONGODB_INITIAL_PRIMARY_ROOT_USER |
Primary node root username (necessary for arbiter and secondary nodes) | root |
MONGODB_SET_SECONDARY_OK |
Mark node as readable. Necessary for cases where the PVC is lost | no |
MONGODB_DISABLE_ENFORCE_AUTH |
By default, MongoDB authentication will be enforced. If set to true, MongoDB will not enforce authentication | false |
Read-only environment variables
Name | Description | Value |
---|---|---|
MONGODB_VOLUME_DIR |
Persistence base directory | $BITNAMI_VOLUME_DIR/mongodb |
MONGODB_BASE_DIR |
MongoDB installation directory | $BITNAMI_ROOT_DIR/mongodb |
MONGODB_CONF_DIR |
MongoDB configuration directory | $MONGODB_BASE_DIR/conf |
MONGODB_DEFAULT_CONF_DIR |
MongoDB default configuration directory | $MONGODB_BASE_DIR/conf.default |
MONGODB_LOG_DIR |
MongoDB logs directory | $MONGODB_BASE_DIR/logs |
MONGODB_DATA_DIR |
MongoDB data directory | ${MONGODB_VOLUME_DIR}/data |
MONGODB_TMP_DIR |
MongoDB temporary directory | $MONGODB_BASE_DIR/tmp |
MONGODB_BIN_DIR |
MongoDB executables directory | $MONGODB_BASE_DIR/bin |
MONGODB_TEMPLATES_DIR |
Directory where the mongodb.conf template file is stored | $MONGODB_BASE_DIR/templates |
MONGODB_MONGOD_TEMPLATES_FILE |
Path to the mongodb.conf template file | $MONGODB_TEMPLATES_DIR/mongodb.conf.tpl |
MONGODB_CONF_FILE |
Path to MongoDB configuration file | $MONGODB_CONF_DIR/mongodb.conf |
MONGODB_KEY_FILE |
Path to the MongoDB replica set keyfile | $MONGODB_CONF_DIR/keyfile |
MONGODB_DB_SHELL_FILE |
Path to MongoDB dbshell file | /.dbshell |
MONGODB_RC_FILE |
Path to MongoDB rc file | /.mongorc.js |
MONGOSH_DIR |
Path to mongosh directory | /.mongodb |
MONGOSH_RC_FILE |
Path to mongosh rc file | /.mongoshrc.js |
MONGODB_PID_FILE |
Path to the MongoDB PID file | $MONGODB_TMP_DIR/mongodb.pid |
MONGODB_LOG_FILE |
Path to the MongoDB log file | $MONGODB_LOG_DIR/mongodb.log |
MONGODB_INITSCRIPTS_DIR |
Path to the MongoDB container init scripts directory | /docker-entrypoint-initdb.d |
MONGODB_DAEMON_USER |
MongoDB system user | mongo |
MONGODB_DAEMON_GROUP |
MongoDB system group | mongo |
MONGODB_DEFAULT_PORT_NUMBER |
MongoDB port set at build time | 27017 |
MONGODB_DEFAULT_ENABLE_JOURNAL |
Enable MongoDB journal at build time | true |
MONGODB_DEFAULT_DISABLE_SYSTEM_LOG |
Disable MongoDB daemon system log set at build time | false |
MONGODB_DEFAULT_ENABLE_DIRECTORY_PER_DB |
Use a separate folder for storing each database data set at build time | false |
MONGODB_DEFAULT_ENABLE_IPV6 |
Use IPv6 for database connections set at build time | false |
MONGODB_DEFAULT_SYSTEM_LOG_VERBOSITY |
MongoDB daemon log level set at build time | 0 |
MONGODB_DEFAULT_REPLICA_SET_NAME |
Name of the MongoDB replica set at build time | replicaset |
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 themongod
startup command. No defaults -
MONGODB_CLIENT_EXTRA_FLAGS
: Flags to be appended to themongo
command which is used to connect to the (local or remote)mongod
daemon. No defaultsdocker 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® documentationdocker 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 thr
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