Header

How To Deploy Metabase on Ubuntu 20.04 with Docker and DeployHQ

Docker, Java, Open Source, Tips & Tricks, and Tutorials

Post Image

Introduction

Metabase is a Java-based open-source Business Intelligence (BI) tool. It can connect to a number of different databases and has a question builder tool that can hide the complexity of large SQL queries.

In this tutorial you will install Metabase using Docker Compose and DeployHQ for automated deployments, then install Nginx to act as a reverse proxy for your Metabase site. Next, you will enable secure HTTPS connections by using Certbot to download and configure a TLS certificate from the Let's Encrypt Certificate Authority. Finally, you will configure Metabase and load some sample data so that you can experiment with building your own questions and BI dashboards.

Prerequisites

To complete this tutorial, you will need:

  • An Ubuntu 20.04 server with 2 or more CPUs, a non-root user with sudo access, and a firewall. To set this up, follow our Initial Server Setup with Ubuntu 20.04 tutorial.
  • Docker installed. Follow Step 1 and Step 2 of How To Install and Use Docker on Ubuntu 20.04 to install it and configure your non-root user to be able to run docker commands.
  • A DeployHQ account
  • A Git repository to store your configuration
  • A domain name pointed at your server's public IP address

Step 1 — Installing Docker Compose

To install the docker-compose command line tool, first refresh your package list:

sudo apt update

Then install the package using apt:

sudo apt install docker-compose

Note: You can also install a more recent Docker Compose package than the one that is included with Ubuntu 20.04. To do so, follow Step 1 of How To Install and Use Docker Compose on Ubuntu 20.04.

You can confirm that the package is installed by running the following command:

docker-compose --version

You should receive output like the following:

docker-compose version 1.25.0, build unknown
docker-py version: 4.1.0
CPython version: 3.8.10

Step 2 — Setting Up DeployHQ

Before proceeding with the Metabase installation, let's configure DeployHQ for automated deployments:

  1. Log in to your DeployHQ account and create a new project.

  2. Connect your Git repository where you'll store your Metabase configuration files.

  3. Add your server as a deployment destination:

    • Select "Shell Server" as the protocol
    • Enter your server's SSH details
    • Set the deployment path to /home/your_user/metabase
  4. Create your local project structure:

mkdir -p ~/metabase
cd ~/metabase
  1. Configure the following SSH Commands on DeployHQ Dashboard:
# Before SSH Commands
docker-compose down

# After SSH Commands
docker-compose up -d
  1. Create a new file called .gitignore, which should contain the data folder as:
data/

Step 3 — Configuring Metabase with Docker Compose

Create a new file called docker-compose.yml:

nano docker-compose.yml

Add the following configuration:

version: '3'
services:
  metabase:
    # We will always be pulling the latest version available
    image: metabase/metabase:latest
    ports:
      - "127.0.0.1:3000:3000"
    volumes:
      - data:/metabase
volumes:
  data:

Save and exit the file, then add your files to Git:

# These stes are required if you want to keep these settings in git, otherwise you can ignore it
git add docker-compose.yml
git add .gitignore
git commit -m "Initial Metabase setup"
git remote add origin YOUR_REPOSITORY_URL
git push -u origin main

Once you've pushed your changes, go to DeployHQ and start your first deployment:

  1. Navigate to your project in DeployHQ
  2. Click on "Deploy" to start the initial deployment
  3. Review the deployment log to ensure everything is successful

You can test that Metabase is running by using curl:

curl --head http://localhost:3000

You should receive a response with headers indicating that Metabase is running:

HTTP/1.1 200 OK
Date: Tue, 15 Mar 2024 19:26:22 GMT
X-Frame-Options: DENY
...
Server: Jetty(9.4.43.v20210629)

Step 4 — Installing and Configuring Nginx

Install Nginx and configure it to act as a reverse proxy for Metabase:

sudo apt install nginx

Allow public traffic to ports 80 and 443 (HTTP and HTTPS):

sudo ufw allow "Nginx Full"

Create a new Nginx configuration file:

sudo nano /etc/nginx/sites-available/metabase.conf

Add the following configuration (replace your_domain_here with your domain):

server {
    listen       80;
    listen       [::]:80;
    server_name  your_domain_here;
    access_log  /var/log/nginx/metabase.access.log;
    error_log   /var/log/nginx/metabase.error.log;

    location / {
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-Host $host;
      proxy_set_header X-Forwarded-Proto https;
      proxy_pass http://localhost:3000;
  }
}

Enable the configuration:

sudo ln -s /etc/nginx/sites-available/metabase.conf /etc/nginx/sites-enabled/

Verify the configuration:

sudo nginx -t

Reload Nginx:

sudo systemctl reload nginx.service

Step 5 — Installing Certbot and Setting Up TLS Certificates

Install Certbot and its Nginx plugin:

sudo apt install certbot python3-certbot-nginx

Obtain and configure SSL certificates:

sudo certbot --nginx -d your_domain_here

Follow the prompts to:

  • Enter your email address
  • Agree to the terms of service
  • Choose whether to redirect HTTP traffic to HTTPS (recommended)

Certbot will automatically configure Nginx to use the new certificates and reload the service.

Step 6 — Setting Up Metabase

Access your Metabase installation through your browser at https://your_domain_here and follow these setup steps:

  1. Click Let's get started

  2. Configure the following:

    • Select your preferred language
    • Set up your admin account (record your password securely)
    • Choose "I'll add my data later" when prompted to add data
    • Set your usage data preferences
    • Optionally add your email for updates
  3. Click "Take me to Metabase" to access your dashboard

Step 7 — Managing Deployments with DeployHQ

When you need to make changes to your Metabase configuration:

  1. Make changes locally:
cd ~/metabase
# Make your changes to docker-compose.yml or other configuration files
  1. Commit and push your changes:
git add .
git commit -m "Description of your changes"
git push origin main
  1. Deploy through DeployHQ:
  • DeployHQ will automatically detect the new commit
  • Review the changes in DeployHQ's interface
  • Click "Deploy" to apply the changes
  • Monitor the deployment logs for any issues
  1. Verify your changes on the live site

Rolling Back Deployments

If you need to roll back to a previous version:

  1. Navigate to "Deployments" in DeployHQ
  2. Find the last working deployment
  3. Click "Redeploy this version"

Conclusion

You now have a fully functional Metabase installation with:

  • Automated deployments through DeployHQ
  • Docker containerization
  • Secure HTTPS access
  • Nginx reverse proxy
  • Version-controlled configuration

You can now:

  • Connect Metabase to your databases
  • Create custom queries and dashboards
  • Manage configuration changes through Git and DeployHQ
  • Scale your setup as needed

For more information, refer to:

Troubleshooting

Common issues and solutions:

  1. Deployment Failures
  • Check DeployHQ logs for specific error messages
  • Verify your server has sufficient resources
  • Ensure all paths and permissions are correct
  1. Container Issues
  • Use docker-compose logs to check container logs
  • Verify port availability with netstat -tulpn
  • Check system resources with htop
  1. SSL/TLS Issues
  • Verify certificate renewal with certbot certificates
  • Check Nginx error logs: /var/log/nginx/error.log
  • Ensure DNS records are correctly configured

For additional support, consult the respective documentation or community forums.

A little bit about the author

Facundo is the CTO at DeployHQ. He oversees our software engineering team by day and, in his free time, enjoys hobbies such as cycling, spending time in nature, and the company of Bono 🐶

Tree

Proudly powered by Katapult. Running on 100% renewable energy.