Skip to content

Instantly share code, notes, and snippets.

@prashantvc
Last active May 13, 2025 03:24
Show Gist options
  • Save prashantvc/fc30e0907167ccff0ef159a778b699f8 to your computer and use it in GitHub Desktop.
Save prashantvc/fc30e0907167ccff0ef159a778b699f8 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Based on https://gist.github.com/prashantvc/fc30e0907167ccff0ef159a778b699f8
install_and_run_mongodb() {
# 1. Install Docker
echo "Installing Docker..."
curl -fsSL https://get.docker.com -o get-docker.sh > /dev/null 2>&1
sudo sh get-docker.sh > /dev/null 2>&1
echo "Adding user to docker group..."
sudo usermod -aG docker $USER
echo "Docker group updated. New session may be needed for docker commands without sudo."
# Note: 'newgrp docker' is best run manually in a new shell session after this script.
# 2. Install MongoDB via Docker (Option A: Without Authentication)
echo "Starting MongoDB..."
# Ensure the mongo-data directory exists
mkdir -p ~/mongo-data
docker run -d --name mongodb \
-p 27017:27017 \
-v ~/mongo-data:/data/db \
arm64v8/mongo:5.0 --noauth > /dev/null 2>&1
# 3. Verify It's Working
echo "Verifying MongoDB..."
docker ps -f name=mongodb
echo "MongoDB setup complete."
echo "Connect: mongodb://localhost:27017"
echo "Docker group note: New session may be needed for docker commands without sudo."
}
install_and_run_mongodb

Here’s a complete and easy guide to install Docker and run MongoDB on Raspberry Pi OS (Debian 12).

πŸš€ Full Setup: Docker + MongoDB on Raspberry Pi OS

βœ… 1. Install Docker

Run the official installation script:

curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh

Add your user to the Docker group (to avoid using sudo every time):

sudo usermod -aG docker $USER
newgrp docker

βœ… 2. Install MongoDB via Docker

πŸ”Ή Option A: Without Authentication

docker run -d --name mongodb \
  -p 27017:27017 \
  -v ~/mongo-data:/data/db \
  arm64v8/mongo:5.0 --noauth

βœ… 3. Verify It's Working

docker ps

You should see mongodb running.

βœ… 4. Connect to MongoDB

  • Without auth:

    mongo mongodb://localhost:27017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment