Skip to content

Deploy a Metabase instance using Docker Compose and optionally protect it with an SSL certificate

Notifications You must be signed in to change notification settings

MilhosOU/metabase-docker-compose

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 

Repository files navigation

metabase-docker-compose

Easily deploy Metabase using Docker container with this simple setup. It targets port 80, allowing you to access the Metabase instance directly through your IP address in a browser.

Prerequisites

  • Docker and Docker Compose installed on your system.

Set Up

  1. Create a directory called Metabase
mkdir metabase
cd metabase
  1. Create a ´docker-compose.yml´ file with the following content:
version: '3'
services:
  metabase:
    image: metabase/metabase:latest
    ports:
      - 80:3000
    environment:
      MB_DB_TYPE: postgres
      MB_DB_DBNAME: metabase
      MB_DB_PORT: 5432
      MB_DB_USER: metabase
      MB_DB_PASS: metabase
      MB_DB_HOST: postgres
  postgres:
    image: postgres:latest
    environment:
      POSTGRES_USER: metabase
      POSTGRES_DB: metabase
      POSTGRES_PASSWORD: metabase
    volumes:
      - ./pg:/var/lib/postgresql/data
  1. Pull the required Docker image
docker-compose pull
  1. Start the Metabase and PostgreSQL containers:
docker-compose up

Update Metabase

From time to time, Metabase releases new versions with feature improvements, bug fixes, or security patches. It's a good practice to keep your Metabase instance up-to-date. Here are the steps to update Metabase:

  1. Stop Nginx Service (if running):

    Before making any changes, especially if you have set up HTTPS as shown above, ensure the Nginx service is stopped.

    sudo systemctl stop nginx 
  2. Stop Current Docker Services:

    Ensure your Metabase and PostgreSQL services are stopped before updating.

    docker-compose down
  3. Pull the Latest Metabase Image:

    This step fetches the latest version of the Metabase Docker image.

    docker pull metabase/metabase:latest
  4. Start Nginx Service:

    If you're using Nginx for SSL termination, start it back up.

    sudo systemctl start nginx
  5. Restart Docker Services:

    Now, with the updated Metabase image, start the services again.

    docker-compose up

(OPTIONAL) Create HTTPS Certificate

⚠️ Warning: You need to update your docker-compose.yml. Change the port mapping from 80:3000 to 3000:3000.

  1. Stop the Docker Compose services:
docker-compose down
  1. Update the package list and install Certbot:
sudo apt-get update
sudo apt install -y certbot python3-certbot-apache
  1. Generate SSL certificates using Certbot:
sudo certbot certonly --standalone -d example.com --preferred-challenges http --agree-tos -m your@email.com --keep-until-expiring
  1. Copy the generated certificates to your project directory:
sudo cp -r /etc/letsencrypt/live/example.com ./certs
sudo chown -R $USER:$USER ./certificates
  1. Install Nginx:
sudo apt update
sudo apt install nginx
  1. Create a new Nginx configuration file:
sudo touch /etc/nginx/sites-available/example.com
  1. Add the following configuration to the file, replacing example.com with your domain and YOUR_APP_IP:3000 with the IP and port of your application:
server {
    listen 80;
    server_name example.com;
    return 301 https://$host$request_uri;
}

server {
    listen 443 ssl;
    server_name example.com;

    ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;

    location / {
       proxy_pass http://YOUR_APP_IP:3000;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}
  1. Create a symbolic link to the sites-enabled directory:
sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/
  1. Test the Nginx configuration:
sudo nginx -t
  1. Restart Nginx:
sudo systemctl restart nginx
  1. Start the Docker Compose services:
docker-compose up

About

Deploy a Metabase instance using Docker Compose and optionally protect it with an SSL certificate

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published