
📘 Introduction
Deploying Redis and MongoDB 4.x on a Raspberry Pi means dealing with ARM compatibility, container networking, and security best practices. Redis is fully multi-architecture, while MongoDB requires using version 4.x on Pi to avoid ARMv8.2-A dependency errors. You’ll install Docker on the Pi, deploy both services with Docker Compose, manage your Pi from Windows 11 using Docker Contexts, set up TLS encryption for Redis, and review secure options for GUI management.
🔧 Setting Up Docker on Raspberry Pi
Remove old Docker/podman packages:
sudo apt-get remove docker docker-engine docker.io containerd runc podman-docker
Add the official Docker repository and install Docker Engine + Compose
sudo apt-get update
sudo apt-get install ca-certificates curl gnupg lsb-release
curl -fsSL https://download.docker.com/linux/raspbian/gpg \
| sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] \
https://download.docker.com/linux/raspbian $(lsb_release -cs) stable" \
| sudo tee /etc/apt/sources.list.d/docker.list
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin
Enable Docker for non-root use and validate the install:
sudo usermod -aG docker $USER && newgrp docker docker run hello-world docker compose version
(Optional) Enable Docker’s remote TCP API (only use over secure LANs):
# /etc/systemd/system/docker.service.d/override.conf
[Service]
ExecStart=
ExecStart=/usr/bin/dockerd \
-H fd:// \
-H tcp://0.0.0.0:2375 \
--containerd=/run/containerd/containerd.sock
🛠 Docker Compose for Redis & MongoDB 4.x
Create docker-compose.yml:
version: '3.8'
services:
redis:
container_name: redis
hostname: redis
image: redis:latest
volumes:
- /home/pi/data/redis/db:/data
ports:
- 6379:6379
networks:
- infra_net
mongo:
container_name: mongo
hostname: mongo
image: mongo:4.0
command: ["mongod", "--bind_ip", "0.0.0.0"]
volumes:
- /home/pi/data/mongo/db:/data/db
- /home/pi/data/mongo/conf/mongod.conf:/etc/mongo/mongod.conf:ro
ports:
- 27017:27017
mem_limit: 250m
mem_reservation: 100m
networks:
- infra_net
networks:
infra_net:
driver: bridge
Run it:
docker compose up -d
Verify:
docker exec -it redis redis-clidocker exec -it mongo mongosh
or, you can just run one by one redis and mo
docker run -d --name redis --hostname redis -p 6379:6379 -v /home/pi/data/redis/db:/data --network infra_net redis:latest
docker run -d --name mongo --hostname mongo -p 27017:27017 -v /home/pi/data/mongo/db:/data/db -v /home/pi/data/mongo/conf/mongod.conf:/etc/mongo/mongod.conf:ro --memory=250m --memory-reservation=100m --network infra_net mongo:4.0 mongod --bind_ip 0.0.0.0
⚙️ ARM Compatibility & Best Practices
- ARM support: Redis works on both ARMv7 and ARMv8; MongoDB requires 4.x on Pi to avoid crashes because newer versions need ARMv8.2-A.
- Troubleshooting tips:
- Ensure neither port 6379 nor 27017 is occupied.
- Confirm folder ownership (
chown -R pi:pi /home/pi/data). - Validate that both services are on the same
infra_netnetwork.
- Best practices:
- Use host volumes for data persistence.
- Restrict port exposure and use authentication.
- Apply memory limits, backups, and monitoring (
docker stats,htop, etc.).
🌐 Section 4: Remote Docker Access from Windows 11
Use Docker Contexts in PowerShell:
docker context create rasperry --docker "host=tcp://192.168.1.150:2375"
docker context use rasperry
docker ps
docker exec -it redis redis-cli
docker context use default
For better security, use an SSH-based context:
docker context create raspberry --docker "host=ssh://pi@192.168.1.150"
docker context use raspberry
At this point, you can create your containers form windows terminal directly as you did before using ssh command. So you can run `docker compose up -d` or the others command.
❗ Note on Docker Desktop UI: Switching contexts works in the CLI but Docker Desktop’s GUI won’t display containers from remote contexts—it only shows the local engine. If you want a GUI to manage your Pi, consider:
- Portainer: run on the Pi or as a Docker Desktop extension—manages multiple hosts over.
- VS Code Remote – Containers: use via SSH to attach to containers on your Pi.
🔐 Configuring Redis with SSL/TLS
- Generate certificates in WSL
sudo apt update && sudo apt install openssl
mkdir -p ~/redis-certs && cd ~/redis-certs
openssl genrsa -out ca.key 4096
openssl req -x509 -new -nodes -key ca.key \
-subj "/C=US/ST=State/L=City/O=Org/CN=MyRedisCA" \
-days 365 -out ca.crt
openssl genrsa -out redis.key 4096
openssl req -new -key redis.key \
-subj "/C=US/ST=State/L=City/O=Org/CN=redis" \
-out redis.csr
openssl x509 -req -in redis.csr -CA ca.crt -CAkey ca.key \
-CAcreateserial -out redis.crt -days 365
mv ca.crt redis.crt redis.key /mnt/c/data/redis/certs/
- Update Compose &
redis.conf
services:
redis:
image: redis:7
container_name: redis
ports:
- "6379:6379"
volumes:
- /c/data/redis/db:/data
- /c/data/redis/certs:/etc/ssl/redis:ro
- /c/data/redis/redis.conf:/usr/local/etc/redis/redis.conf:ro
command: ["redis-server", "/usr/local/etc/redis/redis.conf"]
mem_limit: 1024m
mem_reservation: 250m
networks:
- infra_net
redis.conf
port 0
tls-port 6379
tls-cert-file /etc/ssl/redis/redis.crt
tls-key-file /etc/ssl/redis/redis.key
tls-ca-cert-file /etc/ssl/redis/ca.crt
tls-auth-clients no
- .NET SSL Connection Example
var options = ConfigurationOptions.Parse("localhost:6379");
options.Ssl = true;
options.SslHost = "redis";
var muxer = ConnectionMultiplexer.Connect(options);
...
✅ Conclusion
You now have a full-stack Raspberry Pi setup featuring:
- Docker + Compose and custom networking
- Redis & MongoDB 4.x with ARM compatibility
- Remote Docker management from Windows 11 via CLI contexts
- TLS-secured Redis for encrypted client connections
For a production-grade setup, consider adding TLS for Docker itself, authentication for Redis/MongoDB, automated backup flows, and performance monitoring tools.
📚 References
- Docker Desktop in Win11 can’t connect to Docker Engine running on remote Ubuntu 24.01 LTS
- Docker GUI to control remote Docker host
- Docker contexts
- Enable Redis TLS in Compose
- MongoDB 4.x compatibility on Pi
- Docker Desktop GUI limitations – Docker Forums
- Using Portainer for multi-host GUIs
- VS Code Remote Containers with SSH