Skip to content
Home » How to Install Uptime Kuma in Docker with MariaDB on the Host?

How to Install Uptime Kuma in Docker with MariaDB on the Host?

  • by

The previous article explained how to install the Kuma uptime application using Docker and using the MariaDB database which also runs on Docker. This article will explain about installing the Kuma uptime application using Docker but using MariaDB on the host.

 

Problem

How to install uptime kuma in docker with MariaDB on the host?

 

Solution

Here are the steps to install the kuma uptime application using docker but using MariaDB on the host:

1. Configure MariaDB

Make sure you have installed the MariaDB database on your server and then change the file /etc/mysql/mariadb.conf.d/50-server.cnf in the bind-address section to be as below:

bind-address            = 0.0.0.0

 

Next, restart MariaDB using the command:

sudo systemctl restart mariadb

 

After that, access to MariaDB and run the command below:

CREATE DATABASE uptime_kuma;
CREATE USER 'kuma-user'@'%' IDENTIFIED BY 'kumapass123';
GRANT ALL PRIVILEGES ON uptime_kuma.* TO 'kuma-user'@'%';
FLUSH PRIVILEGES;
\q

 

2. Create a docker compose file

Create a compose folder in the /opt folder using the command below:

sudo mkdir -p /opt/compose/uptime-kuma/
cd /opt/compose/uptime-kuma/

 

After that, create a docker-compose.yaml file and copy the script below:

services:
  uptime-kuma:
    image: louislam/uptime-kuma:2
    container_name: uptime-kuma
    restart: unless-stopped
    ports:
      - "3001:3001"
    extra_hosts:
      - "host.docker.internal:host-gateway"
    environment:
      UPTIME_KUMA_DB_TYPE: mariadb
      UPTIME_KUMA_DB_HOSTNAME: host.docker.internal
      UPTIME_KUMA_DB_PORT: 3306
      UPTIME_KUMA_DB_NAME: ${MARIADB_DATABASE}
      UPTIME_KUMA_DB_USERNAME: ${MARIADB_USER}
      UPTIME_KUMA_DB_PASSWORD: ${MARIADB_PASSWORD}
    volumes:
      - kuma-data:/app/data

volumes:
  kuma-data:

 

After that, create a .env file like the below script (The value must be the same as the value you ran the query in MariaDB):

MARIADB_DATABASE=uptime_kuma
MARIADB_USER=kuma-user
MARIADB_PASSWORD=kumapass123
MARIADB_ROOT_PASSWORD=qwerty

 

Run the below command to turn on the docker compose:

docker compose up -d

 

To check if the containers are running or not, use the command below:

docker ps

 

After you type the commands, your screen will show up similar to the one below:

Check the running container

 

3. Configure webserver

If you use Apache, create a file at /etc/apache2/sites-available/kuma.conf and copy the script below to the file:

<VirtualHost *:80>
ServerName yourdomain.com
DocumentRoot /var/www/html/

ProxyPass / http://localhost:3001/
RewriteEngine on
RewriteCond %{HTTP:Upgrade} websocket [NC]
RewriteCond %{HTTP:Connection} upgrade [NC]
RewriteRule ^/?(.*) "ws://localhost:3001/$1" [P,L]

ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>

 

then run the command below:

sudo a2enmod rewrite
sudo a2enmod proxy
sudo a2enmod proxy_http
sudo a2ensite kuma.conf

 

Check if there is an error in Apache and if there is no error, reload Apache using the command below:

apachectl -t
sudo systemctl reload apache2

 

INFO
If your server is running an nginx webserver, then in the file /etc/nginx/conf.d/uptime-kuma.conf insert the script below:

server {
    listen 80;
    server_name uptime-kuma.yourdomainname.com;

    location / {
        proxy_pass         http://localhost:3001;
        proxy_http_version 1.1;
        proxy_set_header   Upgrade $http_upgrade;
        proxy_set_header   Connection "upgrade";
        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;

        # Added WebSocket support
        proxy_set_header   Sec-WebSocket-Key $http_sec_websocket_key;
        proxy_set_header   Sec-WebSocket-Version $http_sec_websocket_version;
        proxy_set_header   Sec-WebSocket-Extensions $http_sec_websocket_extensions;

        # Improve performance of this reverse proxy
        proxy_buffering    off;
    }

    # Redirect HTTP to HTTPS if needed for encryption
    # Uncomment the following lines if you have SSL enabled
    # return 301 https://$host$request_uri;
}

 

Use the command below to check if there is an error in the nginx configuration and then reload nginx:

sudo nginx -t
sudo systemctl reload nginx

 

4. Access uptime kuma

Open your browser, and type:

http://ip_server:3001

 

then there will be a display like below:

Fill in the columns for the admin account

 

Enter in the columns above the value you want and press the Create button then a display will appear similar to the image provided below:

Display of uptime kuma

 

If you want to make sure uptime kuma use MariaDB database, run the command below:

docker logs uptime-kuma | grep DB

 

Your screen will appear similar to the picture shown below:

Check the running database

If you want to monitor the website, click the Add New Monitor button at the top left, an image similar to the one shown will appear:

Create a new host or a website to monitor in uptime kuma

 

Fill in the required fields (at least fill in the Monitor Type, Friendly Name, and URL columns) and press the Save button, then the host you have filled in will look like in the image below:

Monitor the host or the website

 

If you just want to display the status without displaying many attributes then you can click the Status Pages button at the top right of the site like the image below:

Click the Status Page button

 

After you press the Status Page button, the following image will appear: 

Create the Status Page page

 

Click the New Status Page button, and an image will appear similar to the one shown below:

Create the Status Page page

 

Enter the name and slug you want (I wrote the sites for the name and slug), then press the Next button, then there will be a display as below:

Insert the host or the monitor in the Status Page

 

Enter the host you want to display on the Status Page, after that click the Save button, then there will be a display as below:

Display of Status Page

 

You can see that the hosts to be monitored look simpler and you can give the URL to other parties to also monitor these hosts.

 

Note

Go to this page if you want to backup the MariaDB database and for how to restore the database, you can go to this page.

 

References

sysadminpedia.com
magnus919.com
uptimekuma.org

image_pdfimage_print
Visited 1 times, 1 visit(s) today

Leave a Reply

Your email address will not be published. Required fields are marked *