Quick Setup: Configure Superset with Docker

Configure Superset with Docker Compose, Docker file and Shell script

Maliha Sameen
Towards Data Engineering
4 min readMay 28, 2023

--

Apache Superset (Source: https://censius.ai/blogs/apache-superset-review)

In this tutorial, you walk through a simplified approach to configure Apache Superset (data exploration and visualization tool) with Docker Compose. Unlike the traditional method that involves cloning the Superset’s Github repository, this method offers a more simplified, structured and hassle free setup process.

In this tutorial, you will do the following:

  • Create Superset Configuration Files i.e. superset-init.sh and superset_config.py
  • Dockerfile Configuration
  • Docker Compose Configuration
  • Running the Superset Container

To ensure smooth configuration process without worrying about incorrect path, please follow the directory structure outlined below:

├───superset
├───dockerfile
├───superset_config.py
└───superset-init.sh
└───docker-compose.yml

Prerequisites:

Before proceeding, make sure you have the following prerequisites:

  • Docker installed on your system
  • Basic familiarity with Docker Compose
  • Familiarity with Apache Superset

Create Superset Configuration Files:

Create superset-init.sh

First things first, we need a shell script that starts the initialization of Superset using Superset CLI to create admin user, set roles and permissions and start superset server.

Step 1: Create an admin user in Superset with details (username, first name, last name, email, and password).

The values for these parameters are passed through docker compose file but they can also be set manually before running the script.

Step 2: Upgrade the Superset Metastore to ensure we have the latest Superset version during the initialization process.

Step 3: Initialize Superset by setting up default roles and permissions.

Step 4: Finally the /usr/bin/run-server.sh script is executed to start the server. This allows users to have access to the Superset web interface and start using the application.

Here’s the shell script code for the above steps.

Please note that this file will be mounted into the docker container in dockerfile configuration section.

So far, we have created the shell script to start the Superset initialization process. Next, we’ll provide custom configuration settings to Superset, before we move on to configure the dockerfile.

Create superset_config.py

This file will contain Superset-specific settings and customizations that you can use to override the default parameters that already come with Superset base image. You can checkout the default parameters here.

You must define the SECRET_KEY parameter even if you want to go with all default parameters. It must be any long random string.

Here is a sample config file to get you started.

We have created both configuration files that we will be using in our dockerfile configuration next.

Dockerfile Configurations

In this section, we will create a Dockerfile that extends base image of Apache Superset. It will define all the steps needed to build a custom Superset container image

Step 1: Extend from the base image apache/superset:latest .

Step 2: Switch to root user to perform administrative tasks inside docker container.

Step 3: In order to connect to any database from Superset, you need to install the respective database driver. mysqlclient is a python package installed to connect MySQL to Superset.

All database drivers for superset can be found on this link.

Step 4: Define environment variables (username, admin, password) to be used for creating superset admin user. The values for these parameters are passed from docker-compose.yml.

Step 5: Mount superset-init.sh and superset_config.py into the docker container and specify SUPERSET_CONFIG_PATH to point to superset_config.py path inside the docker container.

Step 6: Switch back to superset user to run the Superset application.

Step 7: Specify the entrypoint for the container, which is the superset-init.sh script. This will initiate the superset setup.

Here is the complete code for dockerfile.

So, we are also done with the dockerfile configuration. Now let’s use this dockerfile in our docker-compose.yml to build the superset image.

Docker Compose Configurations

Let’s create the docker compose file to define the Superset service for deployment. We will specify the build context path, environment variables and port mapping between host and container.

Once you’ve defined the docker compose file, you can run the superset container.

Running the Superset Container

With the configuration files in place, we can now launch the Superset container using Docker Compose. We’ll execute two simple commands to start the Superset container.

# Build docker compose file
docker compose build

# Start the container
docker compose up -d

Once the Superset container is up and running, the web interface can be accessed on localhost:8088. From here, you can login using the admin credentials provided in the docker compose file and start using the interface.

That’s it!

Congratulations! You have successfully configured Apache Superset using Docker Compose in a simplified manner. You can explore the powerful features of Apache Superset and create beautiful charts and dashboards.

If you liked this tutorial, please hit the clap and follow my profile Maliha Sameen.

References:

[1] https://github.com/pausros/Docker/tree/ba781348a685d00629928f73024a8d1238fca50e/Lab6/reto/superset

[2] https://hub.docker.com/r/apache/superset

--

--