Docker Metabase



  • MySQL is an open source relational database management system. Based in Structured Query Language (SQL), MySQL can run on most platforms and is mainly used for web-based applications.
  • The HEAD of development on the Metabase repository. Use at your own risk.
  • Metabase is built and packaged as a Java jar file and can be run anywhere that Java is available. Below we provide detailed instructions on how to install and run Metabase in a variety of common configurations. Running the Jar File This is the simplest and most basic way of running Metabase.
  1. Metabase Docker Compose
  2. Metabase Sqlite
  3. Metabase Docker Compose
  4. Metabase Open Source
  5. Metabase Docker Update

Metabase provides an official Docker image via Dockerhub that can be used for deployments on any system that is running Docker. If you’re trying to upgrade your Metabase version on Docker, check out these upgrading instructions. Launching Metabase on a new container. You can use docker logs -f metabase to follow the rest of the initialization progress. Once the Metabase startup completes you can access the app at localhost:3000. Since Docker containers have their own ports and we just map them to the system ports as needed it’s easy to move Metabase onto a different system port if you wish.

Metabase is an open source dataviz application that lets you create analytics graphs and dashboards very easily. Let's see how to deploy Metabase over HTTPS by using Docker, Nginx and Let's Encrypt.

Note: this post won’t cover how to use metabase, we just focus on how tomake it work over https with Nginx and Docker.

Prerequisite

Before we start, you should be familiar with the following tools:

  • Metabase (at least what it’s useful for)
  • Docker and docker-compose
  • Nginx reverse proxy
  • Let’s encrypt and Certbot

You should have Docker, docker-compose and Nginx installed beforewe can go on.

I am also going to assume you already have a domain name ready to redirect toyour metabase application and a server to host the app.

Overview

Metabase

Here’s an overview of the environment we will setup:

  • domain.com/metabase: Assuming your domain name is domain.com, we willserve the application under the url domain.com/metabase.
  • Metabase container: We will use the officialMetabase Docker Image, theapplication will run on localhost:3000.
  • Nginx reverse proxy: Since the application runs on localhost:3000, itis not accessible to the public yet. With nginx, we will redirect the trafficfrom domain.com/metabase to localhost:3000.
  • Metabase db: Metabase needs to store its metadata in a dedicated database.This database could be postgresql or a simple .h2 file, we use the laterfor more simplicity.
  • sqlite.db: This will our main database, the one that contains the datawe want to visualize with metabase. Note that Metabase is compatiblewith many databases like Postgres, MySQL, Mongo DB, sqlite, etc …

Let’s recap everything on a schema:

Setup Metabase container

We use docker-compose for setting upthe container, here’s the docker-compose.yml configuration file:

Run metabase locally with:

Setup Nginx reverse proxy

Nginx reverse proxy will listen on port 80, and redirect the traffic from/metabase to your local metabase application, running on localhost:3000.

Before using HTTPS, let’s configure Nginx to redirect the traffic as explainedabove:

Then, you can use Certbot and Let’s encrypt to add HTTPS to the website. Youcan follow the instructions onCertbot’s website.Once you’re done, you will see that your nginx configuration file was editedby certbot to add the SSL certificates. It may look something like this:

Conclusion

Metabase Docker Compose

Now you should be good to go, the Metabase application should successfullyappear under https://domain.com/metabase. You can proceed to the configurationof your databases, as explained on the Metabase documentation

Note that we passed the db.sqlite database as a volumeto the docker container (in docker-compose.yml: ./db.sqlite:/db.sqlite).So when Metabase will ask where your sqlite database is located, you willhave to write /db.sqlite.

I hope this post was useful, don’t hesitate to let me know in the comments.

v0.39.0.1 / Troubleshooting Guide / Docker

While Docker simplifies a lot of aspects of running Metabase, there are a number of potential pitfalls to keep in mind.

If you are having issues with Metabase under Docker, we recommend going through the troubleshooting process below. Then look below for details about the specific issue you’ve found.

Troubleshooting Process

  1. Check that the container is running
  2. Check that the server is running inside the container
  3. Check whether Metabase is using the correct application database
  4. Check that you can connect to the Docker host on the Metabase port
  5. Check that you can connect to the container from the Docker host
  6. Check that you can connect to the server from within the container

Specific Problems

Metabase container exits without starting the server

Run docker ps to see if the Metabase container is currently running. If it is move on to the next step.

If docker ps does not show the running container, then list the stopped containers by running:

docker ps -a | grep metabase/metabase

Docker metabase/metabase

And look for the container that exited most recently. Note the container ID.Look at that container’s logs with:

Docker logs CONTAINER_ID

Metabase Container is running but the Server is not

How to detect this:

Run docker ps to make sure the container is running

The server should be logging to the Docker container logs. Check this by running:

docker logs CONTAINER_NAME

You should see a line like this at the beginning:

and eventually:

If you see the below lines:

How to fix this:

Check this for errors about connecting to the application database.Watch the logs to see if Metabase is still being started:

Docker Metabase

Docker logs -f CONTAINER_ID

will let you see the logs as they are printed.

If the container is being killed before it finished starting it could be a health check timeout in the orchestration service used to start the container, such as Docker Cloud, or Elastic Beanstalk.

If the container is not being killed from the outside, and is failing to start anyway, this problem is probably not specific to Docker. If you are using a Metabase-supplied image, you should open a GitHub issue.

Not connecting to a remote application database

How to detect this:

If this is a new Metabase instance, then the database you specified via the environment variables will be empty. If this is an existing Metabase instance with incorrect environment parameters, the server will create a new H2 embedded database to use for application data and you’ll see lines similar to these:

How to fix this:

Double check you are passing environments to Docker in the correct way.You can list the environment variables for a container with this command:

Metabase Sqlite

docker inspect some-postgres -f '{{ .Config.Env }}'

The Metabase server isn’t able to connect to a MySQL or PostgreSQL database

How to detect this:

The logs for the Docker container return an error message after the “Verifying Database Connection” line.

How to fix this:

Try to connect with mysql or psql commands with the connection string parameters you are passing in via the environment variables.

If you can’t connect to the database, the problem is due to either the credentials or connectivity. Verify that the credentials are correct. If you are able to log in with those credentials from another machine then try to make the same connection from the host running the Docker container.

Metbase

One easy way to run this is to use Docker to start a container that has the appropriate client for your database. For Postgres this would look like:

docker run --name postgres-client --rm -ti --entrypoint /bin/bash postgres

Then from within that container try connecting to the database host using the client command in the container such as psql. If you are able to connect from another container on the same host, then try making that connection from within the Metabase Docker container itself:

docker exec -ti container-name bash

And try to connect to the database host using the nc command and check if the connection can be opened:

nc -v your-db-host 5432

This will make it clear if this is a network or authentication problem.

The Metabase application database is not being persisted

How to detect this:

This occurs if you get the Setup screen every time you start the application. The most common root cause is not giving the Docker container a persistent filesystem mount to put the application database in.

How to fix this:

Make sure you are giving the container a persistent volume

The internal port isn’t being remapped correctly

How to detect this:

Run docker ps and look at the port mappingRun curl http://localhost:port-number-here/api/health. This should return a response with a JSON response like:

How to fix this:

Make sure to include a -p 3000:3000 or similar remapping in the docker run command you execute to start the Metabase container image.

Metabase can’t write or read to/from a file or directory

How to detect this:

A message in the logs will clearly indicate an IOError/Permission denied from Java, or errors from SQLite with the org.sqlite.core.NativeDB._open_utf8 form.

Metabase Docker Compose

How to fix this:

Ensure that the user who is running Metabase has permission to read and write to the file or directory:

Docker Metabase
  • If you are running Metabase as a JAR file in your local machine or server, check the user who is running the Java process.
  • If you’re running Metabase from the Docker container, make sure you’re using the /metabase.db directory.

If you’re running Metabase from the JAR in any *nix (Unix like) operating system, in order to see which user is running Metabase, you have to open a terminal and type ps -uA | grep metabase.

Metabase Open Source

Helpful tidbits

How to get to the shell in the Metabase container

docker exec -ti CONTAINER_NAME bash

How to get the logs for the Metabase container

Metabase Docker Update

docker logs -f CONTAINER_NAME