Running ipinfo.tw on dokku

To obtain my external IP, I chose to use ipinfo.tw. Initially, I fetched my IP via https://ipinfo.tw, but I decided to host it on my own server.

I prefer using Dokku to run applications, manage subdomains, and handle encryption. Below are the steps to make ipinfo.tw work with Dokku.

Since ipinfo.tw runs on Docker, we need to set up a reverse proxy. Dokku handles this with Nginx. According to the ipinfo.tw server-side documentation, we must add the following line to the generated Nginx configuration file:

proxy_set_header X-Real-IP $remote_addr;

To run the application on Dokku via a Docker image, we need to customize the Nginx configuration file. We can define the nginx.conf.sigil file, which Dokku uses during the application build process. This file should be present in the Docker image's working directory. For more details, refer to the Dokku documentation on customizing the Nginx configuration.

Follow these steps:

  1. Download the nginx.conf.sigil template file from Dokku's GitHub repository.
  2. Add proxy_set_header X-Real-IP $remote_addr; after the proxy_set_header definitions.


Next, create a Dockerfile with the following instructions:

FROM peterdavehello/ipinfo.tw:latest

USER root
ADD nginx.conf.sigil /etc/nginx/nginx.conf.sigil
RUN chown -R nginx:nginx /etc/nginx/nginx.conf.sigil
WORKDIR /etc/nginx

USER nginx

I chose to create a GitHub repository to build and push the Docker image to hub.docker.com, but you can also do it manually.

Once the Docker image is ready to pull, we can create the application with Dokku. The nginx.conf.sigil configuration file will be automatically detected and used as a template to generate the nginx.conf file for the application.

Make sure to add the Dokku Let's Encrypt plugin from https://github.com/dokku/dokku-letsencrypt before running the following commands:

$ dokku apps:create ipinfo
$ dokku git:from-image ipinfo example/ipinfo.tw:latest
$ dokku ports:set ipinfo http:80:8080
$ dokku domains:set ipinfo ipinfo.example.com
$ dokku letsencrypt:enable ipinfo

You should see your remote ip address when accessing your application at ipinfo.example.com.

Pierre FILSTROFF

Senior Software Engineer - IC - Ruby on Rails/Hotwire - Android/iOS - DevOPS