Self-Host Metabase with Docker on a VPS
In this article
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
- Update your system
SSH into your VPS and run:sudo apt update && sudo apt upgrade -y - Install Docker and Docker Compose
Install Docker using the official convenience script:curl -fsSL https://get.docker.com -o get-docker.shsudo sh get-docker.sh
Verify installation:docker --version
Docker Compose is included as a plugin. Check with:docker compose version - Create a project directory
Make a folder for Metabase:mkdir ~/metabase && cd ~/metabase - Create a docker-compose.yml file
Use a text editor (nano or vim) to createdocker-compose.ymlwith 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:Replaceyour_strong_passwordwith a secure password (e.g., useopenssl rand -base64 32). - Start the containers
Run:docker compose up -d
This will pull images and start both services. Check status:docker compose ps - Access Metabase
Open your browser and go tohttp://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). - 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 (replaceyourdomain.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 -tsudo systemctl restart nginx - 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. - Configure firewall
If you have UFW enabled, allow SSH, HTTP, and HTTPS:sudo ufw allow OpenSSHsudo ufw allow 80/tcpsudo ufw allow 443/tcpsudo 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
latesttag pulls updates, but you need to manually rundocker compose pullanddocker compose up -dto apply them.
Tips
- Use environment variables for secrets – Instead of hardcoding passwords in the compose file, use a
.envfile and reference variables like${MB_DB_PASS}. - Back up the Postgres volume – Regularly back up the
pgdatavolume usingdocker 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 -fto debug issues.
Troubleshooting
- Metabase won't start – Check logs:
docker compose logs metabase. Common causes: wrong DB credentials, Postgres not ready. Ensure thedepends_onhas 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
- 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.
- 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.
- How do I update Metabase? – Run
docker compose pullthendocker compose up -d. This will recreate the container with the latest image. - Is Metabase free? – The open-source version is free. There are paid enterprise features, but the core is open source.
- 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. - Why is my Metabase slow? – Check your VPS resources. Metabase needs at least 2GB RAM. Also, ensure your database queries are optimized.