Sign inSign up

axterbach/rpi-mongodb

By axterbach

Updated over 1 year ago

MongoDB for Raspberry Pi 4

Image
Databases & storage
0

10K+

axterbach/rpi-mongodb repository overview

Quick Reference

Supported Tags

  • latest: Latest stable version
  • 7.0.0: Specific version

Supported Architectures

ArchitectureAvailable
x86-64
arm64/v8
armhf

Description

MongoDB image for Raspberry Pi. It is based on Unofficial MongoDB Docker Image for Raspberry Pi. Check the original source for details.

If you are on the Pi 4, these custom MongoDB binaries are necessary because your hardware does not meet the minimum microarchitecture requirements.

For all of you on the Pi 5, I recommend using the official MongoDB docker images since the Pi 5 meets the minimum hardware requirements for MongoDB.

Usage

To help you get started creating a container from this image you can either use docker compose or the docker run CLI commands.

⚠️ Note: Unless a parameter is flaged as Optional, it is mandatory and a value must be provided.

---
services:
  rpi-mongodb:
    image: axterbach/rpi-mongodb:latest
    container_name: rpi-mongodb
    environment:
      MONGO_AUTHSOURCE: admin
      MONGO_INITDB_ROOT_USERNAME: root
      MONGO_INITDB_ROOT_PASSWORD: <change_me>
      #MONGO_DBNAME: <change_me>  # Optional
      #MONGO_USER: <change_me>    # Optional
      #MONGO_PASS: <change_me>    # Optional
    volumes:
      - <local_path_to_mongodb_data>:/data/db
      - ./init-mongo.sh:/docker-entrypoint-initdb.d/init-mongo.sh:ro  # Optional
    restart: unless-stopped

⚠️ Note: Set <change_me> and <local_path_to_mongodb_data> with your own values.

If you want to create additional user and database set values for: MONGO_DBNAME, MONGO_USER and MONGO_PASS and remove comment from those 3 lines. Also, create a init-mongo.sh file with the content below.

#!/bin/bash

if which mongosh > /dev/null 2>&1; then
  mongo_init_bin='mongosh'
else
  mongo_init_bin='mongo'
fi

# Execute only if MONGO_USER, MONGO_PASS & MONGO_DBNAME are deffined.
if [ -z "${MONGO_USER}" ] || [ -z "${MONGO_PASS}" ] || [ -z "${MONGO_DBNAME}" ]; then
  exit 0
fi

"${mongo_init_bin}" <<EOF
use ${MONGO_AUTHSOURCE}
db.auth("${MONGO_INITDB_ROOT_USERNAME}", "${MONGO_INITDB_ROOT_PASSWORD}")
db.createUser({
  user: "${MONGO_USER}",
  pwd: "${MONGO_PASS}",
  roles: [
    { db: "${MONGO_DBNAME}", role: "dbOwner" },
    { db: "${MONGO_DBNAME}_stat", role: "dbOwner" }
  ]
})
EOF
For docker run
docker run -d \
  --name=rpi-mongodb \
  -e MONGO_AUTHSOURCE=admin \
  -e MONGO_INITDB_ROOT_USERNAME=root \
  -e MONGO_INITDB_ROOT_PASSWORD=secret_password \
  -e MONGO_DBNAME=test_db `# Optional` \
  -e MONGO_USER=test_usr `# Optional` \
  -e MONGO_PASS=secret_password `# Optional` \
  -v /path/to/mongodb/data:/data/db \
  -v ./init-mongo.sh:/docker-entrypoint-initdb.d/init-mongo.sh:ro  `# Optional` \
  --restart unless-stopped \
  axterbach/rpi-mongodb:latest

⚠️ Note: Set your own values for: MONGO_INITDB_ROOT_PASSWORD, MONGO_DBNAME, MONGO_USER, MONGO_PASS and /path/to/mongodb/data parameters.

Environment Variables

VariableDescription
MONGO_AUTHSOURCEMongoDB special database. Default is admin.
MONGO_INITDB_ROOT_USERNAMEMongoDB root user. Default is root.
MONGO_INITDB_ROOT_PASSWORDSet the password for MongoDB root user.
MONGO_DBNAMESpecify the name of a database to be created (valid only for first run).
MONGO_USERSpecify the name of new user account (valid only for first run).
MONGO_PASSSet the password for new user account (valid only for first run).

Tag summary

Content type

Image

Digest

sha256:219eec5ac

Size

132.2 MB

Last updated

over 1 year ago

docker pull axterbach/rpi-mongodb