docs/devcontainer/getting-started.md
This guide will walk you through setting up your MongoDB development environment using Dev Containers.
Dev Containers require Docker to be installed and running on your system. Choose one of the following Docker providers:
Rancher Desktop is our recommended Docker provider for devcontainer development.
Installation:
dockerd (moby) ⚠️ Important!Recommended Settings: After installation, increase resources for better build performance:
Tip: More resources = faster builds. MongoDB builds benefit significantly from additional CPU cores and memory.
IMPORTANT!: If you already have VSCode open when you install Rancher Desktop, make sure to restart VSCode otherwise it may not find the Docker socket and VSCode will prompt you to install Docker Desktop instead.
Docker Desktop is a popular alternative.
Note on Licensing: Docker Desktop may require a paid license for commercial use. Please review the licensing terms to ensure compliance with your use case.
Installation:
OrbStack is a lightweight, fast Docker alternative for macOS.
Note on Licensing: OrbStack may require a paid license for commercial use. Please review the licensing terms to ensure compliance with your use case.
Installation:
For Linux users, you can use Docker Engine directly.
Installation: Follow the official guide: docs.docker.com/engine/install
⚠️ Critical: You must have a
~/.sshdirectory on your host machine before building the devcontainer. The devcontainer requires this directory to exist, regardless of whether you use SSH or HTTPS to clone the repository.
# On your HOST machine (not inside the container)
mkdir -p ~/.ssh
If you skip this step, you'll encounter bind mount errors when trying to start the devcontainer.
Download and install VS Code from code.visualstudio.com
To clone the repository using SSH (recommended for contributors), you'll need SSH keys configured with GitHub.
⚠️ Important: Run all commands in this section on your host machine (not inside the container). SSH keys need to be set up before cloning the repository into the container.
# Check for existing SSH keys
ls -la ~/.ssh/id_*.pub
# If you see id_rsa.pub, id_ed25519.pub, or similar, you have keys
If you don't have SSH keys, generate them:
# Generate a new ED25519 key (recommended)
ssh-keygen -t ed25519 -C "[email protected]"
# Or generate RSA key (if ED25519 not supported)
ssh-keygen -t rsa -b 4096 -C "[email protected]"
# Press Enter to accept default location
# Enter a passphrase (recommended) or press Enter for no passphrase
Copy your public key:
# For ED25519
cat ~/.ssh/id_ed25519.pub
# For RSA
cat ~/.ssh/id_rsa.pub
Add to GitHub:
Test your connection:
ssh -T [email protected]
# Should see: "Hi username! You've successfully authenticated..."
If your SSH key has a passphrase, add it to the SSH agent:
# Start ssh-agent (macOS/Linux)
eval "$(ssh-agent -s)"
# Add your key to the agent
ssh-add ~/.ssh/id_ed25519 # or id_rsa
# Verify key is loaded
ssh-add -l
macOS users: Add this to ~/.ssh/config to automatically load keys:
Host *
AddKeysToAgent yes
UseKeychain yes
IdentityFile ~/.ssh/id_ed25519
For passphrase-protected keys, also add to ~/.zshrc or ~/.bashrc:
ssh-add --apple-use-keychain ~/.ssh/id_ed25519 2>/dev/null
Windows users: The ssh-agent service should start automatically. If not:
# In PowerShell (as Administrator)
Get-Service ssh-agent | Set-Service -StartupType Automatic
Start-Service ssh-agent
Note: VS Code automatically forwards your SSH agent to the container, so your keys will be available inside the devcontainer.
Learn more about using SSH keys with GitHub →
For optimal performance, especially on macOS, clone the repository directly into a Docker volume rather than your local filesystem. This is crucial for Bazel performance.
Open VS Code Command Palette
Cmd+Shift+PCtrl+Shift+PRun Clone Command
Dev Containers: Clone Repository in Named Container Volume...Enter Repository URL
[email protected]:10gen/mongo.git
Or use HTTPS:
https://github.com/mongodb/mongo.git
[email protected]:mongodb/mongo.git
Or use HTTPS:
https://github.com/mongodb/mongo.git
Tip: SSH URLs are recommended if you have SSH keys configured
Choose Volume Name
mongo-workspacedocker volume lsWait for Initial Setup
Let's make sure everything is working correctly.
# Verify GCC version
gcc --version
# Verify Python version
python3 --version
The devcontainer automatically sets up a Python virtual environment:
# Should already be activated (check for (python3-venv) in prompt)
which python
# Should show: /workspaces/mongo/python3-venv/bin/python
# Check poetry is available
poetry --version
Try building a target:
bazel build install-mongod
This may take a while on first run but verifies:
The following extensions should be installed and active:
Check: View → Extensions and verify they're enabled.
Your code lives in a Docker volume, not your local filesystem. To access it:
/workspaces/mongo (default workspace folder)Several volumes persist data across container restarts:
engflow_auth → ~/.config/engflow_auth
mongo-cache → ~/.cache
mongo-python3-venv → /workspaces/mongo/python3-venv
mongo-bashhistory → /commandhistory
MongoDB data directory is automatically created at /data/db with proper permissions.
Problem: Clone fails with "Permission denied (publickey)" or "[email protected]: Permission denied"
Solution:
# Test SSH connection from your HOST machine (before starting container)
ssh -T [email protected]
# If this fails, your SSH keys aren't set up correctly
# Follow the SSH key setup instructions above
# Check if ssh-agent has your key
ssh-add -l
# If empty, add your key
ssh-add ~/.ssh/id_ed25519 # or id_rsa
# If you see "Could not open a connection to your authentication agent"
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519
Problem: SSH works on your host machine but fails inside the container
Cause: SSH agent forwarding may not be working
Solution:
# On your HOST machine, ensure ssh-agent is running with your keys
ssh-add -l # Should list your keys
# If not listed, add them
ssh-add ~/.ssh/id_ed25519
# In VS Code, rebuild the container
# Command Palette → "Dev Containers: Rebuild Container"
VS Code SSH Agent Forwarding: The Dev Containers extension automatically forwards your SSH agent, but this requires:
~/.ssh/)Learn more about sharing git credentials →
Problem: Docker build fails with "no space left on device"
Solution:
# Clean up Docker
docker system prune
# Increase Docker disk space in Docker Desktop/Rancher Desktop settings
Problem: Bazel builds are very slow
Solution:
Problem: Python commands not found or using wrong version
Solution:
# Manually activate
source /workspaces/mongo/python3-venv/bin/activate
# Reinstall dependencies
poetry install --no-root --sync
Problem: clangd, ESLint, or other extensions show errors
Solution:
# Rebuild compile_commands.json for clangd
bazel build compiledb --config=local
# Restart VS Code window
# Cmd/Ctrl+Shift+P → "Developer: Reload Window"
If you prefer to clone locally first (not recommended for best performance):
Clone the repository to your local machine:
git clone [email protected]:10gen/mongo.git
cd mongo
Open in VS Code:
code .
Open Command Palette (Cmd/Ctrl+Shift+P)
Run: Dev Containers: Reopen in Container
⚠️ Note: This uses bind mounts and may have performance issues on macOS with Bazel.