Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Self-Host Metabase with Docker on a VPS

· 5 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

This guide walks you through deploying Metabase, an open-source business intelligence tool, on your own VPS using Docker. You'll end up with a fully functional analytics dashboard accessible via your domain or IP, with data stored in a persistent Postgres database. Before starting, ensure you have a VPS with a public IP, SSH access, and a domain name (optional but recommended).

What You'll Need

  • A VPS running Ubuntu 22.04 or 24.04 (other Linux distros work too, but commands may vary).
  • SSH access with sudo privileges.
  • Docker and Docker Compose installed. If not, we'll install them.
  • A domain name pointing to your VPS IP (optional, for HTTPS).
  • Ports 80 and 443 open in your firewall (if using a domain).

Step-by-Step

  1. Update your system
    SSH into your VPS and run:
    sudo apt update && sudo apt upgrade -y
  2. Install Docker and Docker Compose
    Install Docker using the official convenience script:
    curl -fsSL https://get.docker.com -o get-docker.sh
    sudo sh get-docker.sh
    Verify installation:
    docker --version
    Docker Compose is included as a plugin. Check with:
    docker compose version
  3. Create a project directory
    Make a folder for Metabase:
    mkdir ~/metabase && cd ~/metabase
  4. Create a docker-compose.yml file
    Use a text editor (nano or vim) to create docker-compose.yml with the following content:
    version: '3.9'
    
    services:
      metabase:
        image: metabase/metabase:latest
        container_name: metabase
        restart: always
        ports:
          - "3000:3000"
        environment:
          MB_DB_TYPE: postgres
          MB_DB_DBNAME: metabase
          MB_DB_PORT: 5432
          MB_DB_USER: metabase
          MB_DB_PASS: your_strong_password
          MB_DB_HOST: postgres
        depends_on:
          - postgres
    
      postgres:
        image: postgres:16
        container_name: metabase-postgres
        restart: always
        environment:
          POSTGRES_DB: metabase
          POSTGRES_USER: metabase
          POSTGRES_PASSWORD: your_strong_password
        volumes:
          - pgdata:/var/lib/postgresql/data
    
    volumes:
      pgdata:
    Replace your_strong_password with a secure password (e.g., use openssl rand -base64 32).
  5. Start the containers
    Run:
    docker compose up -d
    This will pull images and start both services. Check status:
    docker compose ps
  6. Access Metabase
    Open your browser and go to http://your_server_ip:3000. You'll see the setup screen. Follow the prompts to create your admin account and connect a database (you can skip connecting a database for now).
  7. Set up a reverse proxy with Nginx (optional but recommended)
    Install Nginx:
    sudo apt install nginx -y
    Create a config file:
    sudo nano /etc/nginx/sites-available/metabase
    Add the following (replace yourdomain.com):
    server {
        listen 80;
        server_name yourdomain.com;
    
        location / {
            proxy_pass http://localhost:3000;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto $scheme;
        }
    }
    Enable the site and restart Nginx:
    sudo ln -s /etc/nginx/sites-available/metabase /etc/nginx/sites-enabled/
    sudo nginx -t
    sudo systemctl restart nginx
  8. Enable HTTPS with Let's Encrypt (optional)
    Install Certbot:
    sudo apt install certbot python3-certbot-nginx -y
    Run:
    sudo certbot --nginx -d yourdomain.com
    Follow the prompts. Certbot will auto-renew via a systemd timer.
  9. Configure firewall
    If you have UFW enabled, allow SSH, HTTP, and HTTPS:
    sudo ufw allow OpenSSH
    sudo ufw allow 80/tcp
    sudo ufw allow 443/tcp
    sudo ufw enable

Common Mistakes

  • Not using a persistent database – If you don't set up Postgres, Metabase stores its data in an embedded H2 database inside the container, which is lost when the container is recreated. Always use Postgres for production.
  • Weak passwords – Using 'password' or '123456' for the DB password is a security risk. Use a strong random one.
  • Exposing port 3000 directly – If you skip the reverse proxy, your Metabase instance is accessible on port 3000 without encryption. This is fine for testing but not for production.
  • Forgetting to set restart policy – Without restart: always, your containers won't auto-start after a reboot.
  • Not updating Metabase – The latest tag pulls updates, but you need to manually run docker compose pull and docker compose up -d to apply them.

Tips

  • Use environment variables for secrets – Instead of hardcoding passwords in the compose file, use a .env file and reference variables like ${MB_DB_PASS}.
  • Back up the Postgres volume – Regularly back up the pgdata volume using docker run --rm -v metabase_pgdata:/var/lib/postgresql/data -v $(pwd):/backup alpine tar czf /backup/metabase_backup.tar.gz -C /var/lib/postgresql/data .
  • Use a custom network – The default bridge network is fine, but for better isolation, define a custom network in the compose file.
  • Monitor logs – Check logs with docker compose logs -f to debug issues.

Troubleshooting

  • Metabase won't start – Check logs: docker compose logs metabase. Common causes: wrong DB credentials, Postgres not ready. Ensure the depends_on has a condition (e.g., condition: service_healthy) or add a healthcheck to Postgres.
  • Cannot access Metabase on port 3000 – Check if the container is running: docker ps. If not, check logs. Also verify firewall rules: sudo ufw status.
  • HTTPS not working – Ensure Nginx config is correct and that DNS points to your VPS IP. Test with curl -I https://yourdomain.com.
  • Database connection errors after restart – If Postgres data volume is corrupted, you may need to restore from backup or recreate the volume. Always back up.

Frequently Asked Questions

  1. Do I need a domain name to use Metabase? – No, you can access it via IP, but a domain is recommended for HTTPS and easier access.
  2. Can I use SQLite instead of Postgres? – Yes, but it's not recommended for production because it's not designed for concurrency and data loss risk.
  3. How do I update Metabase? – Run docker compose pull then docker compose up -d. This will recreate the container with the latest image.
  4. Is Metabase free? – The open-source version is free. There are paid enterprise features, but the core is open source.
  5. Can I use Docker volumes for backups? – Yes, you can back up the entire volume, but it's easier to use a database dump (e.g., pg_dump) for logical backups.
  6. Why is my Metabase slow? – Check your VPS resources. Metabase needs at least 2GB RAM. Also, ensure your database queries are optimized.