Welcome to Your Interactive Guide

This interactive application will walk you through setting up your own self-hosted services using Docker and Cloudflare. Each section is broken down into manageable steps with easy-to-copy code blocks. Navigate using the menu on the left to begin.

How It Works: System Overview

Before we start, let's look at the big picture. This diagram shows how the pieces you're about to set up fit together. A secure "Tunnel" connects the Cloudflare network directly to the Docker applications on your server, making them accessible to you on your domain without exposing your server directly to the internet.

Your Domain(e.g., example.com)
Cloudflare NetworkSSL & Security
Secure Tunnel(cloudflared)
Your ServerNightscout, Diasync

Before You Begin: Domain Name

A domain name (like `your-site.com`) is required. We recommend purchasing and managing it through Cloudflare, as it simplifies this entire process. If you prefer a hands-off approach, fully managed hosting and domain services are also available.

Part 1: Installing Docker 🐳

The first step is to install Docker on your Linux server. Docker is the platform that will run our applications in isolated environments called containers. Follow the steps below, running each command in your server's terminal.

1

Install Docker

This command downloads and runs the official Docker installation script.

sudo curl -fsSL https://get.docker.com | sh
2

Enable Docker Service

This ensures Docker starts automatically whenever your server reboots.

sudo systemctl enable docker
3

Start Docker

Manually starts the Docker service for the current session.

sudo systemctl start docker
4

Add User to Docker Group

This important step allows you to run Docker commands without `sudo`.

sudo usermod -aG docker $USER
5

Apply Group Changes

Applies the group change to your current terminal session. You may need to log out and back in for it to take full effect.

newgrp docker
6

(Optional) Enable Autocompletion

These commands enable terminal autocompletion for Docker, making it easier to type commands.

sudo apt install -y bash-completion && sudo curl -L https://raw.githubusercontent.com/docker/cli/master/contrib/completion/bash/docker -o /etc/bash_completion.d/docker && [[ -f /etc/bash_completion ]] && source /etc/bash_completion && source /etc/bash_completion.d/docker
echo -e '\n# Enable Docker CLI autocompletion\nif [ -f /etc/bash_completion ]; then\n  . /etc/bash_completion\n  source /etc/bash_completion.d/docker\nfi' >> ~/.bashrc
source ~/.bashrc

Part 2: Setting Up Directories & Files 📂

With Docker installed, we now prepare the environment. This involves creating a persistent storage volume for our data, making folders to keep things organized, and downloading the pre-built configuration files.

1

Create Docker Volume

Creates a managed storage volume named `nightscout_mongo_data` to safely store the Nightscout database.

docker volume create nightscout_mongo_data
2

Create Project Folders

Creates a set of folders in your home directory to organize the configuration for each service.

mkdir ~/nightscout ~/cloudflared ~/diasync
3

Clone Diasync Repository

Downloads the `diasync` application source code into its folder.

cd ~/diasync
gh repo clone kirbyok/diasync-production .
4

Download Cloudflared Files

Navigates into the `cloudflared` folder and downloads its `docker-compose.yml` and `env.txt` files.

cd ~/cloudflared
wget https://xstor.novagrid.cloud/Cloudflared/docker-compose.yml
wget https://xstor.novagrid.cloud/Cloudflared/env.txt
5

Download Nightscout Files

Navigates into the `nightscout` folder and downloads its configuration files.

cd ~/nightscout
wget https://xstor.novagrid.cloud/nightscout/docker-compose.yml
wget -O env.txt https://xstor.novagrid.cloud/Cloudflared/env.txt
6

Rename Configuration Files

Renames the downloaded `env.txt` files to `.env`. Docker automatically looks for this filename to load environment variables.

mv ~/cloudflared/env.txt ~/cloudflared/.env
mv ~/nightscout/env.txt ~/nightscout/.env

Part 3: Editing Your Configuration Files ✍️

This is a crucial step where you personalize the setup. You will edit the `.env` files to add your unique tunnel token and Nightscout settings. We recommend using the simple text editor `nano` for this.

3.1 Cloudflared (`~/cloudflared/.env`)

Follow these steps to get your unique Tunnel Token from the Cloudflare dashboard and add it to the configuration file.

  1. Log in to your **Cloudflare Dashboard**.
  2. On the left sidebar, go to **Zero Trust**.
  3. Navigate to **Access** > **Tunnels**.
  4. Click **Create a tunnel**, choose **Cloudflared** as the connector type, give your tunnel a name (e.g., "my-server"), and save it.
  5. On the next screen, you will be given a long token string. **Copy only the token part.**
  6. Open the file for editing by running: nano ~/cloudflared/.env
  7. Paste your token after the `=` sign for the `TUNNEL_TOKEN` variable.
# .env file for cloudflared
TUNNEL_TOKEN=YOUR_REALLY_LONG_TOKEN_FROM_CLOUDFLARE_DASHBOARD

3.2 Nightscout (`~/nightscout/.env`)

This file requires more customization. Open it with nano ~/nightscout/.env, then **delete the template `TUNNEL_TOKEN` line** and add the critical variables shown below. Your `API_SECRET` must be at least 12 characters long and kept secret.

MONGO_CONNECTION_STRING=mongodb://mongo/nightscout
API_SECRET=YourSuperSecretPassword123
DISPLAY_UNITS=mg/dl
ENABLE=careportal basal boluscalc cage iage bage iob cob sage
DEVICESTATUS_ADVANCED=true
THEME=colors

Part 4: Launching Services & Final Configuration 🚀

With all the configuration complete, it's time to bring your services to life. We will start the core applications, configure the public-facing hostname in Cloudflare, and then set up the final piece, Diasync.

4.1 Launch Cloudflared and Nightscout

Run the following commands to start the Cloudflare tunnel and Nightscout application. The `-d` flag runs them in the background.

Start Cloudflared:

cd ~/cloudflared
docker compose up -d

Start Nightscout:

cd ~/nightscout
docker compose up -d

4.2 Configure Cloudflare Public Hostname

You must now tell your tunnel how to direct traffic to your Nightscout site. This makes it accessible from the internet via your domain.

  1. Go back to your **Cloudflare Tunnel dashboard** and click **Configure** on your tunnel.
  2. Select the **Public Hostname** tab and click **Add a public hostname**.
  3. **Subdomain:** Enter a name like `nightscout`.
  4. **Domain:** Select your domain name.
  5. **Service Type:** Select `HTTP`.
  6. **URL:** Enter nightscout:1337.
  7. Click **Save hostname**. Your site will now be live at `https://nightscout.yourdomain.com`.

4.3 Configure and Launch Diasync

This final service syncs your CGM data. Run the `make start` command to begin the interactive setup script, which will prompt you for your CGM and Nightscout details.

Run interactive setup:

cd ~/diasync
make start

Launch the container:

After the script finishes, launch the Diasync container to start syncing.

docker compose up -d

Part 5: Verifying Everything is Running ✅

Congratulations, the setup is complete! Let's run a couple of final commands to confirm that all three of your services (`cloudflared`, `nightscout`, `diasync`) are active and running correctly.

Check Running Containers

The `docker ps` command lists all active Docker containers. You should see three entries in the output, one for each service.

cd ~
docker ps

Check Container Stats

The `docker stats` command provides a live view of the CPU, memory, and network resources your containers are using. This is a great way to see that they are "alive". Press `Ctrl+C` to exit the live view.

docker stats

All Done!

Your self-hosted Nightscout and Diasync services are now fully operational and accessible at the public hostname you configured.