Hello, I hope you are doing well.

Today I would like to tell you about running Metabase with Docker. First of all, what is Metabase? According to its website Metabase is fast analytics with the friendly UX and integrated tooling to let your company explore data on their own. I think it is more like open source version of Tableau where business or data analyst can connect to many data source, get the data, learn the data, and even make visualization based on the data (CMIIW).

Here is the docker compose file that I created to run Metabase and PostgreSQL. You can start it by running docker compose up -d command, and stop it by running docker compose down.

# docker-compose.yaml
services:
  metabase:
    image: metabase/metabase:v0.47.5
    container_name: metabase
    environment:
      MB_DB_TYPE: postgres
      MB_DB_DBNAME: metabase
      MB_DB_PORT: 5432
      MB_DB_USER_FILE: /run/secrets/db_user
      MB_DB_PASS_FILE: /run/secrets/db_password
      MB_DB_HOST: postgres
      JAVA_TIMEZONE: Asia/Jakarta
    ports:
      - 3000:3000
    secrets:
      - db_password
      - db_user
    healthcheck:
      test: curl --fail -I http://localhost:3000/api/health || exit 1
      interval: 15s
      timeout: 5s
      retries: 5
    volumes:
      - /dev/urandom:/dev/random:ro
    restart: unless-stopped
    depends_on:
      postgres:
        condition: service_healthy
  postgres:
    image: postgres:15-alpine
    container_name: postgres
    environment:
      POSTGRES_DB: metabase
      POSTGRES_USER_FILE: /run/secrets/db_user
      POSTGRES_PASSWORD_FILE: /run/secrets/db_password
    ports:
      - 5432
    secrets:
      - db_password
      - db_user
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -d metabase -U database-user"]
      interval: 10s
      timeout: 5s
      retries: 5
    volumes:
      - ./postgres-data:/var/lib/postgresql/data
    restart: unless-stopped
secrets:
  db_password:
    file: db_password.txt
  db_user:
    file: db_user.txt

db_password.txt file

database-user

db_password.txt file

database-password

Don’t forget to make a server backup schedule since the database is in the same server and not using managed service like Amazon RDS or Google Cloud SQL. To ensure you can restore to the previous state in case of emergency. Or, you can spin up a managed database, change the Metabase environment to connect to it, and remove the postgres service from the docker compose file.

That’s all. I hope this article enlighten you about how you can up and running Metabase using only one command.

Thank you.