Docker-compose with persistent configuration settings

I'm using Metabase to connect to a SQLite database and it's been working okay with this configuration:

version: '3.3'
services:
    metabase:
        volumes:
            - /home/gregory/gregory/docker-data/:/metabase
        ports:
            - 3000:3000
        # original docker image
        # image: metabase/metabase
        # my docker image with the default users
        image: gregory/metabase
        restart: always

I was reading up on how to run metabase with docker https://www.metabase.com/docs/latest/operations-guide/running-metabase-on-docker.html#using-postgres-as-the-metabase-application-database

From what I could understand I need to setup a new service with postgres to save the settings. Is that right?
Or can I just set the env variable to a folder next to the docker-compose?

Hi @brunoamaral
You would just set environment variables as recommended by docker-compose.
https://docs.docker.com/compose/environment-variables/

I don't completely understand what you're asking.
If you are currently using H2 as the application database inside the container, then you should migrate away from that, so you don't lose everything if you destroyed the container.
https://www.metabase.com/docs/latest/operations-guide/migrating-from-h2.html

Thanks for that @flamber, my goal is exacty making sure I don't lose users and dashboards once I restart the container.

Right now this is working:

version: '3.3'
services:
    metabase:
        volumes:
            - /home/gregory/gregory/docker-data/:/metabase
            - ./metabase-data:/metabase-data
        environment:
            - MB_DB_FILE=/metabase-data/metabase.db
        ports:
            - 3000:3000
#       image: metabase/metabase
        image: gregory/metabase
        restart: always

But from what I understood of what you said I should include a postgres image in this docker-compose and run the migration steps.

@brunoamaral You should not use H2 in production. Doesn't matter where to store it. Don't use it.
https://www.metabase.com/docs/latest/operations-guide/migrating-from-h2.html

I don't know if you have Postgres running somewhere else or not, but that has more to do with how you run your network than anything specific to Metabase.
Here's an example: https://github.com/metabase/metabase/issues/8401#issuecomment-460182635

Thank you @flamber :slightly_smiling_face:

For anyone trying to setup metabase with a PG db with docker, the following worked for me:

version: '3.3'

services:
    db:
      image: postgres
      restart: always
      environment:
        - POSTGRES_PASSWORD=PASWORD
        - POSTGRES_USER=USERNAME
        - POSTGRES_DB=DATABASE
      ports:
        - 5432:5432
      volumes:
        - ./db-data:/var/lib/postgresql/data
      networks:
        - postgres-network
    metabase:
      volumes:
      # setup your SQLITE db (optional)
        - /PATH/TO/SQLITE/:/metabase
        - ./metabase-data:/metabase-data
      environment:
        - MB_DB_FILE=/metabase-data/metabase.db
        - MB_DB_TYPE=postgres
        - MB_DB_DBNAME=DATABASE
        - MB_DB_PORT=5432
        - MB_DB_USER=USERNAME
        - MB_DB_PASS=PASWORD
        - MB_DB_HOST=db
      ports:
        - 3000:3000
      image: metabase/metabase
      restart: always
      depends_on: 
        - db
      networks:
        - postgres-network
networks:
  postgres-network:
    driver: bridge
1 Like

@brunoamaral Thank you for sharing. You'll want to remove this, since it's not needed, when you're running on Postgres

        - MB_DB_FILE=/metabase-data/metabase.db
1 Like