I’m trying to migrate an existing dockerized H2 installation to an external MySQL database. However, I can’t figure out how to run the database migration commands (as described here) on the docker installation. Am I supposed to run
exec [container id] /bin/bash and then set the new environment variables inside the container?
The default docker command for changing environment variables, i.e:
docker run -d -p 3000:3000 \
-e "MB_DB_TYPE=postgres" \
-e "MB_DB_DBNAME=metabase" \
-e "MB_DB_PORT=5432" \
-e "MB_DB_USER=<username>" \
-e "MB_DB_PASS=<password>" \
-e "MB_DB_HOST=my-database-host" \
--name metabase metabase/metabase
won’t work either, as this will create a new instance and not copy info from my old H2 db. Any suggestions?
This is a long shot, but did you manage to do this?
After being hung up on this unresolved issue, I found a way to temporarily move forward. I’ll be building a custom jar file, and I’d like to migrate an existing demo container using H2 to a Postgres container.
I’m going to try to bind-mount a custom script over the normal
/app/run_metabase.sh entrypoint to accomplish the migration, but I’m sure other people have run into this same issue. It seems like it could work…
Whew, it worked! The only change I had to make to
/app/run_metabase.sh was the last line:
exec su metabase -s /bin/sh -c "exec java $JAVA_OPTS -jar /app/metabase.jar"
exec su metabase -s /bin/sh -c "exec java $JAVA_OPTS -jar /app/metabase.jar $@"
$@ allows passing arguments to the container when it’s run:
docker run --name mig -v /path/data:/metabase-data -v /path/run_metabase.sh:/app/run_metabase.sh -e "MB_DB_TYPE=postgres" -e "MB_DB_PORT=5432" -e "MB_DB_USER=metabase" -e "MB_DB_PASS=metabase" -e "MB_DB_DBNAME=metabase" -e "MB_DB_HOST=metabase-db" -e "MB_DB_FILE=/metabase-data/metabase.db" metabase/metabase load-from-h2
A noteworthy change from what the documentation states: I needed to specify
MB_DB_FILE, and didn’t need to specify the path in to the load command.