Installing and Setting Up MollySocket on a Raspberry Pi with Docker and Portainer
Here's a comprehensive guide to installing and setting up MollySocket on a Raspberry Pi using Docker and Portainer. This approach offers isolation, ease of management, and portability.
Prerequisites:
Raspberry Pi: A Raspberry Pi 4 or 5 is recommended for better performance. Pi 3B+ can work, but may be slower.
Raspberry Pi OS: A fresh install of Raspberry Pi OS (64-bit is highly recommended) is best. Bookworm is the latest as of late 2023/early 2024.
SSH Access: Enable SSH for remote access to your Pi.
Basic Docker Knowledge: Familiarity with Docker concepts like images, containers, and volumes is helpful.
Step 1: Update and Upgrade Raspberry Pi OS
Connect to your Raspberry Pi via SSH and run the following commands:
bash
sudo apt update
sudo apt upgrade -y
Step 2: Install Docker
Use the official Docker installation script for Raspberry Pi:
bash
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 with Docker commands:
bash
sudo usermod -aG docker $USER
newgrp docker # Apply the group change to your current session
Verify Docker installation:
bash
docker run hello-world
Step 3: Install Portainer
Portainer provides a web UI for managing Docker containers.
-d: Runs the container in detached mode (background).
-p 9000:9000: Maps port 9000 on the host (Raspberry Pi) to port 9000 in the container. You can change the host port if desired.
--restart=unless-stopped: Automatically restarts the container unless you explicitly stop it.
-v portainer_data:/data: Creates a volume to persist Portainer's data.
Access Portainer in your web browser: http://<your_raspberry_pi_ip>:9000
Initial Setup: When you first access Portainer, you'll be prompted to create an admin password. Choose a strong password.
Environment: Select "Local" as the environment.
Step 4: Deploy MollySocket with Docker Compose
The easiest way to deploy MollySocket is using Docker Compose. Create a docker-compose.yml file on your Raspberry Pi. You can use a text editor like nano:
bash
nano docker-compose.yml
Paste the following content into the docker-compose.yml file:
yaml
version: "3.9"
services:
mollysocket:
image: ghcr.io/mollysocket/mollysocket:latest
container_name: mollysocket
ports:
- "3000:3000" # Web UI
- "3001:3001" # WebSocket
volumes:
- mollysocket_data:/app/data
restart: unless-stopped
environment:
- TZ=Etc/UTC # Set your timezone (e.g., America/Los_Angeles)
- ENABLE_REGISTRATION=true # Enable user registration (optional)
- ADMIN_PASSWORD=your_admin_password # Set a strong admin password
networks:
- mollysocket_network
volumes:
mollysocket_data:
networks:
mollysocket_network:
driver: bridge
Important Configuration:
ports: Maps the container's ports to the host. 3000 is for the web UI, and 3001 is for the WebSocket connection. Change these if you need to avoid conflicts.
volumes: Creates a volume named mollysocket_data to persist MollySocket's data (messages, users, etc.). This is crucial to prevent data loss when the container is restarted.
restart: unless-stopped: Ensures MollySocket restarts automatically if it crashes or the Pi reboots.
environment:
TZ: Set your correct timezone. Find a list of valid timezones here.
ENABLE_REGISTRATION: Set to true to allow users to register themselves. Set to false if you want to manage users manually.
ADMIN_PASSWORD:CRITICAL: Set a strong password for the admin account. Do not leave this as the default!
Step 5: Deploy MollySocket using Portainer
Login to Portainer: Access Portainer in your web browser.
Select Environment: Choose the "Local" environment.
Add Stack: Click on "Stacks" in the left sidebar, then click "Add stack".
Stack Method: Choose "Web editor".
Paste Compose File: Paste the contents of your docker-compose.yml file into the editor.
Deploy the Stack: Click "Deploy the stack".
Portainer will download the MollySocket image and start the container. You can monitor the deployment process in Portainer.
Step 6: Access MollySocket
Once the stack is deployed successfully, you can access MollySocket in your web browser:
http://<your_raspberry_pi_ip>:3000
Login: Use the admin password you set in the docker-compose.yml file. If you enabled registration, you can create new user accounts.
Troubleshooting:
Port Conflicts: If you encounter port conflicts, change the port mappings in the docker-compose.yml file.
Image Download Errors: Ensure your Raspberry Pi has a stable internet connection.
Container Not Starting: Check the container logs in Portainer for error messages. Common issues include incorrect environment variables or volume mount problems.
Performance: If MollySocket is slow, consider using a faster Raspberry Pi model or increasing the swap space.
Important Security Considerations:
Strong Passwords: Use strong, unique passwords for the admin account and all user accounts.
Firewall: Configure a firewall on your Raspberry Pi to restrict access to MollySocket's ports (3000 and 3001) to trusted networks. ufw is a simple firewall to use.
HTTPS: For production deployments, enable HTTPS to encrypt communication between the client and the server. You can use Let's Encrypt to obtain free SSL certificates. This is beyond the scope of this basic guide, but essential for security.
Regular Updates: Keep Docker, Portainer, and MollySocket updated to the latest versions to benefit from security patches and bug fixes.
This guide provides a solid foundation for running MollySocket on your Raspberry Pi. Remember to customize the configuration to suit your specific needs and prioritize security. Refer to the official MollySocket documentation for more advanced features and configuration options: https://mollysocket.com/docs/