Install Metabase on Google Cloud with Docker on Google App Engine. In this tutorial you are going to learn how to install Metabase and connect it with Cloud SQL with CloudSQL proxy.
This guide demonstrates how to install Java using Docker in App Engine Flexible Environment with app.yaml
and Dockerfile
which is easily scalable.
Prerequisites
- Google Cloud account with billing activated.
- Cloud SQL setup as described here Cloud SQL Second Generation Instance.
- Enable Cloud SQL and Cloud SQL Admin API.
- Install GCloud SDK in your local computer.
Enable APIs and Create New Service account
Go to APIs and Services and click Enable APIs and Services and enable Cloud SQL API
and Cloud SQL Admin API
Go to IAM & Admin >> Service accounts and click Create service account.
In step 1
Enter Service account Name.
Click Create.
In step 2
Select Role.
Cloud SQL >> Cloud SQL Admin Project >> Editor
Click Continue.
In step 3
Click Create Key.
Choose Key type as JSON
Click Create.
Create Cloud SQL Instance
Follow this tutorial to create a new Cloud SQL Second Generation Instance.
Once you have created a user and a database you can proceed to set up the yaml file and Docker file in the local computer.
Setup Cloud SDK
Once you have installed the cloud SDK, run the below command to configure it and choose the project to deploy the Metabase.
Open command prompt or terminal in your local computer and run the following the command.
gcloud init
Follow the onscreen instructions to configure it.
Create Yaml File for Metabase
Create a new directory in your computer named metabase
Open your favorite editor and create a file named app.yaml
inside the metabase
directory.
Copy the below code and add this in your app.yaml
file.
runtime: custom env: flex manual_scaling: instances: 1 env_variables: MB_DB_TYPE: mysql MB_DB_DBNAME: cloudsql_db_name MB_DB_USER: cloudsql_user_name MB_DB_PASS: cloudsql_password MB_DB_HOST: 127.0.0.1 beta_settings: cloud_sql_instances: cloudsql_connection_name
Replace the cloudsql_db_name, cloudsql_user_name, cloudsql_password, and cloudsql_connection_name with the values of your Cloud SQL instance.
Save your file.
Create Dockerfile for Metabase
Create a new file in the same metabase
directory and name it as Dockerfile
Copy the below code and add this in your Dockerfile
file.
FROM gcr.io/google-appengine/openjdk
EXPOSE 8080
ENV PORT 8080
ENV MB_PORT 8080
ENV MB_JETTY_PORT 8080
ENV MB_DB_PORT 5432
ENV METABASE_SQL_INSTANCE cloudsql_connection_name
ENV JAVA_OPTS "-XX:+IgnoreUnrecognizedVMOptions -Dfile.encoding=UTF-8 --add-opens=java.base/java.net=ALL-UNNAMED --add-modules=java.xml.bind"
ADD https://dl.google.com/cloudsql/cloud_sql_proxy.linux.amd64 ./cloud_sql_proxy
ADD http://downloads.metabase.com/v0.32.9/metabase.jar ./metabase.jar
RUN chmod +x ./cloud_sql_proxy
CMD ./cloud_sql_proxy -instances=$METABASE_SQL_INSTANCE=tcp:$MB_DB_PORT & java -jar ./metabase.jar
Replace the cloudsql_connection_name with your Cloud SQL instance connection name.
Save the file.
Deploy Metabase to App Engine
Open terminal in the metabase
directory.
Run the following command to deploy Metabase to App Engine.
gcloud app deploy
Now, Metabase will be installed on Google App Engine and connected with Cloud SQL.
Once the deployment is completed you will get the url to view your application on the browser.

Conclusion
Now you have learned how to deploy Metabase on Google App Engine Flexible environment.
Installed it all correctly some time ago but I’m not that familiar with GCP and not sure how to update to the latest version of metabase.
I’m having trouble with 502 Bad Gateway
nginx
Me too, you fixed this problem?
Same Here, nothing seems to work
This sounds like the App Engine service is not being properly hosted, perhaps you didn’t expose port 8080 in the dockerfile, or you didn’t include it as an ENV variable in the app.yaml like so (the author didn’t include this bit, not sure why, but it seems essential):
env_variables:
MB_DB_DBNAME: ‘metabase’
MB_DB_TYPE: ”
MB_DB_HOST: ‘172.17.0.1’
MB_DB_PORT: ‘3306’ or ‘5432’
MB_DB_USER: ‘metabase’
MB_DB_PASS: ‘metabase’
MB_JETTY_PORT: ‘8080’
Done, but still I got the 502 message, I’m installing the latest version of Metabase, using Postgres.
hi thank you for this post,
I am getting this error, is there something that I might have not set?
ERROR metabase.core :: Metabase Initialization FAILED
java.lang.Exception: Connection to 127.0.0.1:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
This is simply that App Engine was unable to connect metabase to the backend db. You’ve ensured the app engine service account has Cloud SQL Client or Admin role? And that there is a db in your sql instance named metabase, with the matching user and password combination?