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.
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.
Install Docker
This command downloads and runs the official Docker installation script.
sudo curl -fsSL https://get.docker.com | shEnable Docker Service
This ensures Docker starts automatically whenever your server reboots.
sudo systemctl enable dockerStart Docker
Manually starts the Docker service for the current session.
sudo systemctl start dockerAdd User to Docker Group
This important step allows you to run Docker commands without `sudo`.
sudo usermod -aG docker $USERApply 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(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 ~/.bashrcPart 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.
Create Docker Volume
Creates a managed storage volume named `nightscout_mongo_data` to safely store the Nightscout database.
docker volume create nightscout_mongo_dataCreate Project Folders
Creates a set of folders in your home directory to organize the configuration for each service.
mkdir ~/nightscout ~/cloudflared ~/diasyncClone Diasync Repository
Downloads the `diasync` application source code into its folder.
cd ~/diasync
gh repo clone kirbyok/diasync-production .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.txtDownload 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.txtRename 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/.envPart 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.
- Log in to your **Cloudflare Dashboard**.
- On the left sidebar, go to **Zero Trust**.
- Navigate to **Access** > **Tunnels**.
- Click **Create a tunnel**, choose **Cloudflared** as the connector type, give your tunnel a name (e.g., "my-server"), and save it.
- On the next screen, you will be given a long token string. **Copy only the token part.**
- Open the file for editing by running:
nano ~/cloudflared/.env - Paste your token after the `=` sign for the `TUNNEL_TOKEN` variable.
# .env file for cloudflared
TUNNEL_TOKEN=YOUR_REALLY_LONG_TOKEN_FROM_CLOUDFLARE_DASHBOARD3.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=colorsPart 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 -dStart Nightscout:
cd ~/nightscout
docker compose up -d4.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.
- Go back to your **Cloudflare Tunnel dashboard** and click **Configure** on your tunnel.
- Select the **Public Hostname** tab and click **Add a public hostname**.
- **Subdomain:** Enter a name like `nightscout`.
- **Domain:** Select your domain name.
- **Service Type:** Select `HTTP`.
- **URL:** Enter
nightscout:1337. - 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 startLaunch the container:
After the script finishes, launch the Diasync container to start syncing.
docker compose up -dPart 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 psCheck 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 statsAll Done!
Your self-hosted Nightscout and Diasync services are now fully operational and accessible at the public hostname you configured.