[Dokku] Network understanding

When I ran up Dokku container, I map the host port 8080 to Dokku container port 80. With this configuration, all external requests to Dokku have to reach the host port 8080 first and then they can reach the app deployed by Dokku.

In Dokku container, Dokku server still listens to the port 80, 443, 22. Therefore, the port mapping from host to Dokku container looks like

8080:80
8443:443
5022:22

Again in Dokku container, the app’s nginx should listen to port 80. It’s because external requests will hit host port 8080, then will be converted to Dokku container port 80. Afterwards, Dokku app’s nginx can detect the requests and route them to the matching app according to the domain name.

One thing that is easily to be ignored is that the Dokku container and its app container must be in the same network. Otherwise, Dokku nginx will fail to proxy the requests.

Dokku nginx will proxy the incoming requests to the IP where app container attached and app’s service listen port. We can find this configuration from upstream section in app’s nginx configuration.

dokku nginx:show-config app

At the bottom of the nginx configuration, it looks like

upstream app-3000 {

  server 192.168.240.3:3000;
}

For the app itself, it should expose the port that the service listens to. For example, if the app listens to port 3000, then we should expose port 3000 in the Dockerfile of the project

EXPOSE 3000

If this post helped you to solve a problem or provided you with new insights, please upvote it and share your experience in the comments below. Your comments can help others who may be facing similar challenges. Thank you!
Buy Me A Coffee
DigitalOcean Referral Badge
Sign up to get $200, 60-day account credit !