/ Tech

Easy Dokku and Cloudflare management from the CLI

I regularly find the need for throwing things online; be it files for clients, small/static micro-sites, or documentation for projects. Usually that means a repetitive - if simple - cycle of creating and modifying configuration files and manually configuring mechanisms for file synchronisation.

Fortunately there's an easier way, Dokku: the lightweight heroku-style docker-powered PaaS. I've previously written about how this site is deployed via Dokku, specifically noting how easy and convenient it's been.

Recently I discovered an even easier way to use Dokku though: using the dokku_client.sh script contained in the Dokku repository. This relatively simple little script is executed on your localhost, and handles things such as repository management and executing commands over SSH.

As it's a simple bash script, installation is a breeze; merely requiring you to clone the repository to an appropriate location, set an environment variable (DOKKU_HOST), and configure an alias for the script.

Once installed, running dokku will display a familiar set of commands - exposing all the functionality that you would usually need to access via SSH:

Commands:

    apps       Manage Dokku apps
    certs      Manage Dokku apps SSL (TLS) certs
    checks     Manage zero-downtime settings
    config     Display all global or app-specific config vars
    domains    Manage vhost domains used by the Dokku proxy
    enter      Connect to a specific app container
    events     Show the last events (-t follows)
    help       Print the list of commands
    logs       Show the last logs for an application
    ls         Pretty listing of deployed applications and containers
    nginx      Interact with Dokku's Nginx proxy
    proxy      Manage the proxy used by dokku on a per app
    ps         List processes running in app container(s)
    run        Run a command in the environment of an application
    shell      Spawn dokku shell
    ssh-keys   Manage public ssh keys that are allowed to connect to Dokku
    storage    Mount local volume / directories inside containers
    tags       List all app image tags
    tar        Deploy applications via tarball instead of git
    trace      Enable dokku tracing
    url        Show the first URL for an application (compatibility)
    urls       Show all URLs for an application
    version    Print dokku's version

Now configuring a new dokku application is as simple as typing $ dokku apps:create my-simple-app.

Bonus Tip: Cloudflare DNS Control right from your terminal

Obviously being able to configure server resources from your CLI is awesome, but you still need to configure your DNS records appropriately - and that's often a manual process that requires logging in to some form web control panel.. not cool.

However if you're using Cloudflare, you can use a CLI tool like cloudflare-cli; making DNS updates as easy as a command like this:

$ cfcli -a -t A add my-app 127.0.0.1

The tool linked above also allows you to store authentication details for multiple API accounts in a dot-file (.cfcli.yml) - meaning you can manage multiple Cloudflare accounts with one tool; very useful if you're a contractor, or otherwise responsible for the DNS records of multiple organisations!


Fergus

Contract Software Developer and DevOps Consultant, based out of London in England. Interests include information security, current affairs, and photography.