Deploying Nightscout and tconnectsync on Dokku
Recently I've had to do some digital housekeeping, which resulted in me having to redeploy my Nightscout and tconnectsync instances while migrating servers. I thought I'd write up the process, since I use Dokku, a wonderful self-hosted platform as a service that I haven't really seen mentioned when folks bring up hosting Nightscout.
To start, you'll need Dokku setup on your server. If you're starting on a fresh server like I was, you can follow their Getting Started guide. If you've already got Dokku setup, great! Read on...
Setting up Nightscout #
First of all, we'll setup Nightscout. Since Nightscout relies on MongoDB for data storage, we'll need to set that up before we deploy the app. Fortunately Dokku offers an official plugin which makes it easy to setup and manage Mongo databases.
# Install the Dokku Mongo plugin:
sudo dokku plugin:install https://github.com/dokku/dokku-mongo.git
Next, we'll create the database itself, which is really just a Docker container running Mongo.
dokku mongo:create nightscout
Now, here in October 2026, I ran into some issues... If you get an error message when creating your database, you can click here to read how to fix it before continuing on with this post (I'd like to avoid addressing issues that should be fixed soon in this post).
Next, we'll create a Nightscout app so that we can link our new database to it:
# Create the Nightscout app:
dokku apps:create nightscout
# Link the MongoDB database:
dokku mongo:link nightscout nightscout
The output from the last command should include a MongoDB URL, something that would look like "mongodb://nightscout:blahblahblah@dokku-mongo-nightscout..." – copy this to your clipboard and paste it somewhere you can access it, since we'll need it in an upcoming step.
Now that we've got our database and app setup, let's actually deploy the Nightscout code. To do this, we'll
use Dokku's git:sync command to pull the latest version of Nightscout and build the Docker container locally:
dokku git:sync nightscout --build https://github.com/nightscout/cgm-remote-monitor.git
You'll be prompted with some questions at the end to configure Nightscout. Don't worry, you'll be able to
change these values later. When prompted for your MongoDB URL, paste the mongodb:// string from earlier.
Once you answer all of the questions, Nightscout should be running, but we'll need to make sure it's accessible.
Run dokku ports:list nightscout to see if anything shows up. If not, you'll need to link the HTTP
port 80 to the internal port Nightscout expects traffic on, 1337:
dokku ports:add nightscout http:80:1337
Before we try accessing the fresh instance, let's enable HTTPS to keep it secure. We'll need to install the Dokku
LetsEncrypt plugin and then configure it accordingly. But first, if you haven't already, set the URL you plan on
using for this instance. By default Dokku creates subdomains for each app, so if your global URL is set to
example.com then Dokku will make your Nightscout instance accessible at nightscout.example.com –Â
if you don't want that, set your URL:
dokku domains:set nightscout my-awesome-nightscout.xyz
Once you're comfortable with the URL you'll be using, we can continue on to HTTPS setup:
# Install the plugin:
sudo dokku plugin:install https://github.com/dokku/dokku-letsencrypt.git
# Configure your email address for LetsEncrypt:
dokku letsencrypt:set --global email your-email-address@example.com
# Enable LetsEncrypt on Nightscout:
dokku letsencrypt:enable nightscout
# Enable a cronjob to ensure the SSL certificate stays up-to-date:
dokku letsencrypt:cron-job --add
Now, finally, you should be able to visit your Nightscout instance's URL and see it working! 🎉
Now that we've got Nightscout setup, let's get even more data into it. Since I use a Tandem t:slim x2 insulin pump, I use the open source tconnectsync project to import my pump data to Nightscout. If you don't use a Tandem pump, I'm afraid I can't help you, but chances are there's another project, or even built-in support, to get your pump data into Nightscout.
Setting up tconnectsync #
First, we'll create a new Dokku app for our tconnectsync container:
dokku apps:create tconnectsync
Now, we need to configure the app before we deploy it. I recommend getting everything sorted in a text editor and then copy/pasting the command to set our environment variables. Refer to the tconnectsync installation instructions for the latest information, but for me, I set the following variables:
dokku config:set tconnectsync TIMEZONE_NAME='America/Los_Angeles' TCONNECT_EMAIL='your-email@example.com' TCONNECT_PASSWORD='lol-u-wish' NS_URL='https://my-nightscout.example.com' NS_SECRET='My-Long-Stupid-Secret-Key'
If you need to change something, don't fear, you can keep using dokku config:set to update your variables,
or run dokku config:show tconnectsync to see your current configuration.
Once that's done, we'll pull in the latest published version of the Docker container and run it:
dokku git:from-image tconnectsync ghcr.io/jwoglom/tconnectsync/tconnectsync:latest
This should run the container, and assuming your configuration is correct, it should also import your data to Nightscout. But, by default, tconnectsync runs as a one-off, so we need to tell it to update continuously.
To do that, Dokku needs to pass the --auto-update flag when running the container. We can tell Dokku to do that
with the following command (documented here):
dokku ps:set tconnectsync dockerfile-start-cmd -- '--auto-update'
Just to be safe, I then re-deployed the app with the original git:from-image command from above to verify
that the process continues running with the new flag.
That's all! Hopefully this guide will help folks who run either Dokku or Nightscout or are interested in trying one or the other. Below are some stray thoughts that might help in your journey.
Resources #
- To further customize Nightscout, be sure to read through it's extensive README, but specifically the environment variables section.
- Speaking of environment variables, the
dokku configcommands will be your best friends. - To redeploy, just re-run the commands from above to fetch the latest from the Git repo or container registry. But if you decide that you'd like to modify the code yourself, you can always switch to using Dokku's native Git workflow to utilize Cloud Native Buildpacks or Herokuish Buildpacks.
- To view logs for your applications, use the
dokku logscommand. E.g.dokku logs tconnectsyncordokku logs nightscout