Build Metabase with Docker on Lightsail and make it https with nginx

motivation

――I have a lot of things in BigQuery and Postgres, so I want to query easily. ――I hope you can access it from anywhere. (So ​​I asked for a place that is not local) ――I want to make it as cheap as possible. (If you think about the NPV of investment from the initial investment of home server with RasPi, it should be about 1,000 yen a month) --I want to make it my own domain and https (it is essential if it is .dev) → Replace YOUR-DOMAIN.HERE in the text with your own domain.

What i did

Lightsail settings

--Set the global IP. --In the network settings, open only port 443 used for https. -(SSH 22 is as needed. In my case, I'm working with another Lightsail instance via VPN, so I kept it closed.)

By using our own domain, we pointed the subdomain metabase.YOUR-DOMAIN.HERE to the global IP of the Lightsail instance in the A record.

Create a directory to persist the data in the container

mkdir -p ~/Docker/Metabase ~/Docker/LetsEncrypt ~/Docker/nginx

Arrange a certificate for your own domain with Let's Encrypt

--I used the official image of Certbot. --The reason for using DNS authentication is that it was easy to arrange for multiple domains. --The issued certificates are written to / etc/letsencrypt and are persisted on the host side.

docker run -it --rm \
--name certbot \
-v ~/Docker/LetsEncrypt/cert:/etc/letsencrypt \
certbot/certbot certonly \
--no-self-upgrade \
--manual \
-d metabase.YOUR-DOMAIN.HERE \
-m [email protected] \
--agree-tos \
--preferred-challenges dns-01

Launch Metabase

--I used the official image of Metabase. ――Ulimit seems to be annoying, but I used it as a habit. --The default save destination of Metabase settings is H2, the file creation destination is / metabase-data, and it is mapped to the directory on the host side and made persistent. --If your host is a little more powerful, you could put MySQL or Postgres on its side instead of H2.

docker run --name Metabase -d \
--restart=always \
-v ~/Docker/Metabase:/metabase-data \
-e "MB_DB_FILE=/metabase-data/metabase.db" \
-p 3000:3000 \
--ulimit nproc=4096:4096 \
--ulimit memlock=256000:256000 \
--ulimit nofile=65536:65536 \
metabase/metabase

Configure reverse proxy with nginx

First move to the working directory.

cd ~/Docker/nginx

Create a https.conf file that defines TLS support and behavior as a reverse proxy.

ssl_protocols TLSv1.2;
server {
    listen 443;
    ssl on;
    server_name metabase.YOUR-DOMAIN.HERE;
    ssl_certificate /etc/cert/fullchain1.pem;
    ssl_certificate_key /etc/cert/privkey1.pem;
    location / {
        proxy_pass http://metabase:3000;
        proxy_http_version 1.1;
        proxy_cache_bypass $http_upgrade;
    }
}

Create Dockerfile dockerfile-nginx.

FROM nginx:latest
EXPOSE 443/tcp
ADD https.conf /etc/nginx/conf.d/default.conf

Build the image.

docker build -f dockerfile-nginx -t nginx-tls .

Launch the built set nginx by specifying the certificate.

docker run --name nginx -d \
--restart=always \
--link Metabase:metabase \
-v ~/Docker/LetsEncrypt/cert/archive/metabase.YOUR-DOMAIN.HERE:/etc/cert \
-p 443:443 \
nginx-tls

Set up Metabase

Access https://metabase.YOUR-DOMAIN.HERE/ with a browser and perform the initial settings.

When renewing the certificate

The Let's Encrypt certificate expires in 3 months, so you need to renew it before that. Updates are also done with Certbot. You can automate this with cron.

docker run -it --rm \
--name certbot \
-v ~/Docker/LetsEncrypt/cert:/etc/letsencrypt \
certbot/certbot renew

Note

――Why Docker ... --It's a hassle to run Certbot directly on a Lightsail instance --I don't want to pollute my host through trial and error --I want to limit the memory as needed ――I wouldn't do this for business use --It becomes https with ELB

Enjoy!

Recommended Posts

Build Metabase with Docker on Lightsail and make it https with nginx
[Rails AWS Docker] Build an existing Ruby on Rails + MySQL application with Docker and deploy it on AWS (5)
[Rails AWS Docker] Build an existing Ruby on Rails + MySQL application with Docker and deploy it on AWS (6)
[Rails AWS Docker] Build an existing Ruby on Rails + MySQL application with Docker and deploy it on AWS (3)
[Rails AWS Docker] Build an existing Ruby on Rails + MySQL application with Docker and deploy it on AWS (2)
[Rails AWS Docker] Build an existing Ruby on Rails + MySQL application with Docker and deploy it on AWS (1)
[Rails AWS Docker] Build an existing Ruby on Rails + MySQL application with Docker and deploy it on AWS (4)
[Docker] Build a site on Hugo and publish it on GitHub
Make Docker confusing with Pokemon and make it easier to attach
[docker] [nginx] Make a simple ALB with nginx
Build an environment with Docker on AWS
Make a daily build of the TOPPERS kernel with Gitlab and Docker
I installed Docker on EC2 and started it
Build Elastic Stack with Docker and analyze IIS logs
Until you build a Nuxt.js development environment with Docker and touch it with VS Code
Create a Java (Gradle) project with VS Code and develop it on a Docker container
Easily build Redmine on Windows using WSL2 and Docker
Build WordPress environment with Docker (Local) and AWS (Production)
Create a Java (Maven) project with VS Code and develop it on a Docker container
Apply your own domain to Rails of VPS and make it SSL (https) (CentOS 8.2 / Nginx)
Build Docker Image lightweight and fast with CodeBuild with Santa Banner
Build a Node-RED environment with Docker to move and understand
Elasticsearch> Build with docker, get Twitter information and visualize with Kibana
Create Rails5 and postgresql environment with Docker and make pgadmin available
Maybe it works! Display HTML page from nginx with Docker!
Build docker environment with WSL
Build DynamoDB local with Docker
Build a SPA for Laravel 6.2 / Vue.js / Nginx / Mysql / Redis with Docker
Create a flyway jar with maven and docker build (migrate) with docker-maven-plugin
Build a development environment for Django + MySQL + nginx with Docker Compose
Image Spring Boot app using jib-maven-plugin and start it with Docker
Create a Docker Image for redoc-cli and register it on Docker Hub
Build Couchbase local environment with Docker
Build a Node.js environment with Docker
Build PlantUML environment with VSCode + Docker
Build environment with vue.js + rails + docker
Hello World with Docker and C
Build Rails environment with Docker Compose
WordPress with Docker Compose on CentOS 8
Build Clang x VSCode on Docker (1)
Make JupyterLab run anywhere with docker
Microservices With Docker and Cloud Performance
Build Unity development environment on docker
Build docker + laravel environment with laradock
Build WebRTC Janus with Docker container
Spring Boot gradle build with Docker
Build debug environment on container --Build local development environment for Rails tutorial with Docker-
Enable Docker build cache on GitHub Action and deploy to Amazon ECS
Starting with installing Docker on EC2 and running Yellowfin in a container
If you get stuck with PHPStorm and xdebug on docker. trouble shooting
[Copy and paste] Build a Laravel development environment with Docker Compose Part 2
Put Zabbix in Ubuntu with Docker and monitor Docker on the same host
How to build a Ruby on Rails development environment with Docker (Rails 6.x)
Create a program to post to Slack with GO and make it a container
[Copy and paste] Build a Laravel development environment with Docker Compose Participation
Note: nginx.conf settings for CORS in Exment on Lightsail + Docker (nginx) environment
Build a development environment on AWS EC2 with CentOS7 + Nginx + pm2 + Nuxt.js
How to build a Ruby on Rails development environment with Docker (Rails 5.x)