Running metabase as an AppService on Azure

May 1, 2020

Metabase is an open source analytics tool which allows you to explore and visualize your data. These visualizations can be grouped into dashboards and shared or embedded within or outside of your organization. In this post I will show you how to setup Metabase as an AppService on Azure using the official Docker image and a MySQL database. Creating a Managed MySQL DB

Login to the Azure portal and search for mysql. Select Azure Database for MySQL servers and click Create Azure Database for MySQL server. Next up fill out the necessary details, tags and provision your database instance. Managed services can be quite expensive so be sure to check the estimated monthly cost of the resource. If you intend on following this guide for learning purposes only, be sure to destroy the resource once you are done.

After a few minutes your server will be provisioned and ready to accept connections. Before deploying Metabase we must first ensure we have done the following:

  1. Allow access to Azure services
  2. Add your IP address to the firewall white list
  3. Create a database for the Metabase application
  4. Create a user for the Metabase application with the appropriate access to the Metabase database

Allow Access to Azure Services

On the resource detail page click Connection security under the settings group and then set Allow access to Azure services to Yes. Add IP Address to White List

On the resource detail page click Connection security under the settings group and add your public facing IP address to the firewall white list. Create Database and User

You will need to connect to the server in order to create a database and user for the Metabase application. I use the community edition of DBeaver as a SQL IDE. Connect to the server and run the following command (You can find the connection details under the Connection strings blade on the resource detail page). One thing to note is that any Azure database as a service requires SSL when connecting. In DBeaver you will need to check Use SSL and Require SSL under the SSL tab of the new connection screen.

CREATE DATABASE metabase CHARACTER SET utf8mb4 collate utf8mb4_unicode_ci;
CREATE USER `metabase`@`%` IDENTIFIED BY 'my strong password';
GRANT ALL ON metabase.* TO 'metabase'@'%';
FLUSH PRIVILEGES;

Note the character set and collation above, these are required. Creating an App Service

We are going to deploy metabase using the official Docker image as an AppService on the Azure platform. In the Azure portal search for app services . Select App Services and click Create app service. Fill out the app service details but be sure to select Docker Container under the Publish input. If you are hosting your database on Azure it would be a good idea to set the App Service region to the region in which the database is hosted. On the Docker tab of the wizard select Single Container as the value of Options and Docker Hub as the value of Image Source. Leave Access type as Public and type metabase/metabase as the value of the Image and tag input. You can leave the Startup Command input blank. You can enabled monitoring if you like and don't forget to apply some useful tags. Click create on the Review and Create section of the wizard.

Once you App Service is provisioned we need to set a few environment variables so that Metabase can connect to the MySQL instance. Click on Configuration under the Settings group of the App Service resource detail page. You will be presented with a table of application settings. By default the settings should include DOCKER_REGISTRY_SERVER_PASSWORD, DOCKER_REGISTRY_SERVER_URL, DOCKER_REGISTRY_SERVER_USERNAME and WEBSITES_ENABLE_APP_SERVICE_STORAGE. Leave these values as you found them and add the following settings:

MB_DB_TYPE = "mysql"
MB_ENCRYPTION_SECRET_KEY = "<A randomly generated string of text>"
MB_DB_CONNECTION_URI = "mysql://metabase:<my  strong password>@<server  host>:3306/metabase?useSSL=true&requireSSL=true"

Note you should replace with the password you assigned to the metabase database user and with the server host of your database. The server host is available on the overview page of the Azure Database for MySQL server resource detail page. Once you have assigned your application settings click Save and then click the Restart button on the Overview page.

Give it a few minutes to bring up the container, if you want to track the build progress you can select the Log stream page under the Monitoring group in the side menu. When the container is up navigate to the App Service URL. The URL can be found on the Overview page. You should be presented with the following welcome page.