dokku

Linking two not exposed dokku apps


I have two apps deployed to the same dokku instance, an api service that pulls data from an external api, and an emailer service that hits endpoints on the api service and sends out emails depending on endpoint data. How can I link the emailer app to use the api app possibly using something like an env var API_URL in the emailer app?

The problem is that neither of the services need to be exposed to the web, so I don't want to expose the api service (it only needs to be used by the emailer service)


Solution

  • You can attach both apps to a network to enable inter-app routing, setting the API_URL env var to the correct value based on the name of the app/process type/port combination you are routing to, and then disabling public app proxying. Below is an example of how to perform this task.

    # create a service named internal-network
    dokku network:create internal-network
    
    # attach the apps to the internal-network network
    # if one app needs to be able to immediately talk to another on boot
    # use the `attach-post-create` property instead of `attach-post-deploy`
    dokku network:set api attach-post-deploy internal-network
    dokku network:set emailer attach-post-deploy internal-network
    
    # set the environment variable to talk to api
    # - `api`: the name of the app
    # - `web`: the name of the process
    # - `5000`: the port the container process is listening to, usually 5000
    dokku config:set emailer API_URL=http://api.web:5000
    
    # disable public proxying of the services
    dokku proxy:disable api
    dokku proxy:disable emailer
    
    # rebuild the apps so the containers are attached to the internal-network network
    dokku ps:rebuild api
    dokku ps:rebuild emailer