Skip to content

Instantly share code, notes, and snippets.

@chemicalkosek
Last active June 9, 2022 19:59
Show Gist options
  • Save chemicalkosek/dd7549ebcd244e87890eb94646cbfe0b to your computer and use it in GitHub Desktop.
Save chemicalkosek/dd7549ebcd244e87890eb94646cbfe0b to your computer and use it in GitHub Desktop.
Dokku

Dokku

Creating dokku app

Create the application on the Dokku host. You will need to ssh onto the host to run this command.

 # on the Dokku host
 dokku apps:create my-app-name

Deploy the app

Now you can deploy the my-app-name app to your Dokku server. All you have to do is add a remote to name the app. Applications are created on-the-fly on the Dokku server.

# from your local machine
# the remote username *must* be dokku or pushes will fail
cd your-app-directory
git remote add remote-name dokku@host-adress-or-ip:my-app-name
# Must be pushed to master
git push remote-name master

Domain configuration

Adding a domain before deploying an application will result in port mappings being set. This may cause issues for applications that use non-standard ports, as those will not be automatically detected. Please refer to the proxy documentation for information as to how to reconfigure the mappings.

dokku domains:add <app> <domain> [<domain> ...]      # Add domains to app
dokku domains:add-global <domain> [<domain> ...]     # Add global domain names
dokku domains:clear <app>                            # Clear all domains for app
dokku domains:disable <app>                          # Disable VHOST support
dokku domains:enable <app>                           # Enable VHOST support
dokku domains:remove <app> <domain> [<domain> ...]   # Remove domains from app
dokku domains:remove-global <domain> [<domain> ...]  # Remove global domain names
dokku domains:report [<app>] [<flag>]                # Displays a domains report for one or more apps
dokku domains:set <app> <domain> [<domain> ...]      # Set domains for app
dokku domains:set-global <domain> [<domain> ...]     # Set global domain names

Dokku Let's Encrypt

Instalation

sudo dokku plugin:install https://github.com/dokku/dokku-letsencrypt.git

Commands

$ dokku letsencrypt:help
    letsencrypt:auto-renew                  Auto-renew all apps secured by letsencrypt if renewal is necessary
    letsencrypt:auto-renew <app>            Auto-renew app if renewal is necessary
    letsencrypt:cleanup <app>               Cleanup stale certificates and configurations
    letsencrypt:cron-job <--add|--remove>   Add or remove an auto-renewal cronjob
    letsencrypt:disable <app>               Disable letsencrypt for an app
    letsencrypt:enable <app>                Enable or renew letsencrypt for an app
    letsencrypt:list                        List letsencrypt-secured apps with certificate expiry
    letsencrypt:revoke <app>                Revoke letsencrypt certificate for app

Usage

Obtain a Let's encrypt TLS certificate for app myapp (you can also run this command to renew the certificate):

dokku config:set --no-restart myapp [email protected]
dokku letsencrypt myapp

Once the certificate is installed, you can use the certs:* built-in commands to edit and query your certificate.

You could also use the following command to set an email address for global. So you don't need to type the email address for different application.

dokku config:set --global [email protected]

Note: If you want to automatically renew the certificates, please use dokku letsencrypt:cron-job --add to add an auto-renewal cron-job to the crontab of the dokku user. This is supported starting from the plugin version 0.8.2 which only works with Dokku 0.5 or later.

Environmental Variables

You can set multiple environment variables at once:

dokku config:set node-js-app ENV=prod COMPILE_ASSETS=1

Note: Whitespace and special characters get tricky. If you are using dokku locally you don't need to do any special escaping. If you are using dokku over ssh you will need to backslash-escape spaces:

dokku config:set node-js-app KEY="VAL\ WITH\ SPACES"

If you wish to have the variables output in an eval-compatible form, you can use the config:export command

dokku config:export node-js-app
# outputs variables in the form:
#
#   export ENV='prod'
#   export COMPILE_ASSETS='1'

# source in all the node-js-app app environment variables
eval $(dokku config:export node-js-app)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment