How To Use the Dokku One-Click Install Image to Deploy your App
Note: The Dokku project has changed significantly since this guide was written. The instructions below may not reflect the current state of the Dokku project.
A significant hurdle in developing an application is providing a sane and easy way to deploy your finished product. Dokku is a Platform as a Service solution that enables you to quickly deploy and configure an application to a production environment on a separate server.
Dokku is similar to Heroku in that you can deploy to a remote server. The difference is that Dokku is built to deploy to a single, personal server and is extremely lightweight. Dokku uses Docker, a Linux container system, to easily manage its deployments.
In this guide, we will cover how to deploy your app with Dokku using the DigitalOcean Dokku one-click installation image.
Step One –– Create the Dokku Droplet
The first thing we need to do is create the VPS instance that contains our Dokku installation. This is simple to set up using the DigitalOcean Dokku application.
Click on the "Create" button to create a new droplet:
Name your droplet, and select the size and region that you would like to use:
Scroll down and click on the "Applications" tab. Select the Dokku application image:
Select your SSH keys if you have them available. If you do not already have them configured, now is a great time to create SSH keys to use with your DigitalOcean droplets. This step will help you later.
Click "Create Droplet". Your Dokku VPS instance will be created.
Once your droplet is created, you should set up your domain name to point to your new Dokku droplet. You can learn how to configure domain names with DigitalOcean here.
Step Two –– Access the Droplet To Complete Configuration
You can complete your Dokku configuration by accessing your VPS from a web browser.
If you configured a domain name to point to your Dokku installation, you should visit your domain name with your favorite web browser. If you do not have a domain name configured, you can use your droplet's IP address.
You will be given a simple configuration page. There are a few parts that you need to configure here.
First, check that the Public Key matches the computer that you will be deploying from. This means that if your project is on your home computer, you should use the public key that corresponds to that set up.
If you selected multiple SSH keys to embed during droplet creation, only the first will be available here. Modify it as necessary.
Next, modify the Hostname field to match your domain name. Leave this as your IP address if you do not have a domain name configured.
Choose the way that you want your applications to be referenced. By default, the application will be served like this:
If you select the the "Use virtualhost naming for apps" check box, your apps will be accessible using a virtualhost instead:
Click the "Finish Setup" button to complete the configuration.
Step Three –– Deploy your Application to your Dokku Droplet
At this point, our Dokku droplet is configured and ready to start receiving git repositories, which it will deploy automatically.
This process is as simple as pushing a local git repository to your Dokku droplet. Let's try it out with a sample application.
We will assume that you have already installed git on the computer that houses your project. Clone the sample app we will use with this command:
git clone https://github.com/imchairmanm/demo_application.git
Change into the demo project's directory:
Now, all we have to do is add our Dokku droplet as a remote server.
We can call the remote whatever we'd like, but the name we give the repository will determine how we access the application (if you checked the virtualhost naming option).
git remote add remote_name dokku@your_domain.com:name_to_give_your_app
All that is left to do now is push your app to deploy:
git push remote_name master
You will see the git output and get an application deployed message like this:
-----> Releasing demo ... -----> Deploying demo ... -----> Cleaning up ... =====> Application deployed: http://app_name.your_domain.com To dokku@your_domain.com:app_name * [new branch] master -> masterYou can access your application by going to the URL it gives you:
Your application was pushed to your Dokku droplet and instantly deployed.
If you ever need to delete an app, you can do so by logging into the Dokku droplet through SSH and typing:
dokku delete app_name
As you can see, Dokku leverages some powerful technology to make your app deployment easy and seamless. You can do your configuration and development in whatever environment suits your needs and then deploy to a hands-off production machine.