{"id":2305,"date":"2017-01-17T15:34:28","date_gmt":"2017-01-17T13:34:28","guid":{"rendered":"https:\/\/upcloud.com\/global\/us\/resources\/tutorials\/get-started-dokku-centos\/"},"modified":"2017-01-17T15:34:28","modified_gmt":"2017-01-17T13:34:28","slug":"get-started-dokku-centos","status":"publish","type":"tutorial","link":"https:\/\/upcloud.com\/global\/resources\/tutorials\/get-started-dokku-centos\/","title":{"rendered":"How to Get Started with Dokku CentOS"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Having the freedom of <a href=\"https:\/\/upcloud.com\/global\/products\/cloud-servers\">cloud infrastructure<\/a> can be liberating but sometimes you just want a simple and easy solution to develop and deploy web applications. Dokku is <a href=\"https:\/\/dokku.com\/docs\/getting-started\/installation\/\" target=\"_blank\" rel=\"noreferrer noopener\">an extensible, open-source Platform-as-a-Service<\/a> that can run on any single server of your choosing. With Dokku CentOS you can easily set up your very own PaaS in a very small implementation that is not hungry for server resources. Powered by Docker, Dokku can help you build and manage your application lifecycle in the cloud.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This guide will help you get Dokku CentOS&nbsp;installed, configured, and tested, along with tips on getting the most out of your personal cloud platform. The instructions in this guide are intended for CentOS&nbsp;7, but Dokku is also available on <a href=\"https:\/\/upcloud.com\/global\/resources\/tutorials\/get-started-dokku-ubuntu\/\" target=\"_blank\" rel=\"noreferrer noopener\">Ubuntu<\/a> as well as on <a href=\"https:\/\/upcloud.com\/global\/resources\/tutorials\/get-started-dokku-debian\/\" target=\"_blank\" rel=\"noreferrer noopener\">Debian<\/a>.<\/p>\n\n\n\n<div class=\"wp-block-buttons is-layout-flex wp-block-buttons-is-layout-flex\">\n<div class=\"wp-block-button\"><a class=\"wp-block-button__link wp-element-button\" href=\"https:\/\/signup.upcloud.com\/\">Test hosting on UpCloud!<\/a><\/div>\n<\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Installing Dokku<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Dokku runs on almost any hardware and is well at home in the cloud. To run Dokku, your server should have at least 1GB of RAM which makes the preconfigured 1CPU\/1GB host an ideal starting point for testing your own PaaS.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Start by <a href=\"https:\/\/hub.upcloud.com\/deploy\" target=\"_blank\" rel=\"noopener\">deploying a server<\/a> with at least the minimum requirements.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If you have a domain name available, set the server hostname to a subdomain such as <tt>dokku.example.com.<\/tt>&nbsp;You should&nbsp;configure your DNS provider to point the subdomain including a wildcard to the public IP of your Dokku server. This will allow you to personalise the platform from the get-go.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">We also recommend including your&nbsp;SSH keys to your server at deployment to make logging in more secure and also to make configuring Dokku easier later on. If you have not already added your public SSH keys to your&nbsp;<a href=\"https:\/\/hub.upcloud.com\/account\/ssh\" target=\"_blank\" rel=\"noopener\">UpCloud control panel<\/a>, here is a quick introduction to&nbsp;<a href=\"https:\/\/upcloud.com\/global\/docs\/guides\/managing-ssh-keys\/\" target=\"_blank\" rel=\"noreferrer noopener\">Managing Your SSH Keys<\/a>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Once you have deployed&nbsp;your new Dokku server, follow the steps below to install the platform.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># Install epel for nginx packages to be available\nsudo yum install -y epel-release<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Dokku is built on Docker and employs it to isolate applications, continue by installing Docker with the command below.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># Install Docker\ncurl -fsSL https:\/\/get.docker.com\/ | sudo sh<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Then finally install Dokku and its core dependencies.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># Install Dokku\ncurl -s https:\/\/packagecloud.io\/install\/repositories\/dokku\/dokku\/script.rpm.sh | sudo bash\nsudo yum install -y herokuish dokku\nsudo dokku plugin:install-dependencies --core<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The commands above will install the required dependencies such as Docker Engine and Herokuish along with Dokku CentOS&nbsp;itself.&nbsp;The installation takes only a couple of minutes and works best on a freshly deployed system.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If you get an error saying&nbsp;your hostname could not be resolved or you do not have a domain name available you can use the default reverse DNS name of your UpCloud server for testing. It can be found in your UpCloud control panel in server settings under the <em>IP Addresses<\/em> tab. To change the hostname after deployment, set the system domain name in the <tt>\/etc\/hostname<\/tt> file on your server then&nbsp;restart the host.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Configuring the basic settings<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">When the installation is complete, you will need to add your public SSH key to allow remote application deployment. All keys should be added under the <tt>dokku<\/tt> user account that is used to manage the application. Set at least one SSH key or include multiples each in their own files in the <tt>\/home\/dokku\/.ssh\/<\/tt> folder.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Note: To secure your Dokku host, it is important to complete the web setup process.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/upcloud.com\/media\/dokku-setup-1.png\" alt=\"Dokku setup\" class=\"wp-image-6223\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">If you already included an SSH key at the server deployment it should be stored in <tt>\/root\/.ssh\/authorized_keys<\/tt>. Dokku will edit its own&nbsp;<tt>authorized_keys<\/tt> file for its requirements, and copy the key as a new file into the Dokku user directory.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo cp \/root\/.ssh\/authorized_keys \/home\/dokku\/.ssh\/dokku.pub\nsudo chown dokku:dokku \/home\/dokku\/.ssh\/dokku.pub<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Then include the key file in Dokku.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo dokku ssh-keys:add dokku&nbsp;\/home\/dokku\/.ssh\/dokku.pub<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">In the Dokku CentOS version 0.8.0, virtual host naming for apps&nbsp;is enabled by default. You can verify this by checking that your domain name is set correctly in the&nbsp;<tt>\/home\/dokku\/VHOST<\/tt> file. The feature configures applications under&nbsp;<tt>&lt;app-name&gt;.dokku.example.com<\/tt> subdomains when deployed on Dokku. Make sure to configure a wildcard A record for your domain to allow access to the application subdomains.&nbsp;If you do not have a domain name available, you can use the default reverse DNS name instead, and set it in the <tt>VHOST<\/tt> file.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">A &nbsp; *.dokku.example.com &nbsp; &lt;public IP address&gt;<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Your Dokku CentOS&nbsp;platform should now be installed and ready to deploy applications. Continue below with testing the platform with a simple example app.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Testing&nbsp;the&nbsp;platform<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Dokku integrates well with GitHub and its tools. Deploying applications can be done through git commands from your local machine allowing Heroku-compatible applications to be easily pushed onto a&nbsp;server. The applications are built with Heroku build packs and run isolated in their own containers creating a single-host cloud Heroku setup.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To get the most out of Dokku, you will need a <a href=\"https:\/\/github.com\/\" target=\"_blank\" rel=\"noopener\">GitHub account<\/a>. Sign up if you have not already and <a href=\"https:\/\/help.github.com\/articles\/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent\/\" target=\"_blank\" rel=\"noopener\">add an SSH key to your account<\/a> for secure authentication from your&nbsp;local system. Make sure to add keys to your local SSH agent for both the GitHub and your Dokku server.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Start by creating a new application on your Dokku server using the command below.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># On your Dokku&nbsp;server\ndokku apps:create ruby-rails-sample<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The app will require a Postgres plugin which can be installed with the following command.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># Install Postgres plugin your Dokku server\nsudo dokku plugin:install https:\/\/github.com\/dokku\/dokku-postgres.git<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Then create a new database for the sample app.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># Create a database on your Dokku server\ndokku postgres:create rails-database<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The official datastore offers a method to link the database service to an application. Use the command underneath to enable the sample app to access the database reserved for it.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># Link the database to the application on your Dokku server\ndokku postgres:link rails-database ruby-rails-sample<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">With the Dokku server ready to receive the application, continue by downloading the sample app from GitHub on your local computer. In case you do not already have Git installed, you can find quick installation instructions for many different operating systems over at the&nbsp;<a href=\"https:\/\/git-scm.com\/downloads\" target=\"_blank\" rel=\"noopener\">git download page<\/a>. The commands below are intended to be run on a Linux system.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># On your local&nbsp;system\ngit clone git@github.com:heroku\/ruby-rails-sample.git ~\/ruby-rails-sample<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Then change into the downloaded repository directory and add a new remote location for git that points to your Dokku server with the application name added to the end of the domain name as shown in the example command below. Replace the <tt>&lt;dokku.example.com&gt;<\/tt> with your domain name.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># On your local&nbsp;system\ncd ~\/ruby-rails-sample\ngit remote add dokku dokku@&lt;dokku.example.com&gt;:ruby-rails-sample<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">You can then push the application onto your Dokku server with the following command.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># On your local&nbsp;system\ngit push dokku master<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Once the deployment finishes, the application should be available on your Dokku server at the URL shown at the end of the output <tt>ruby-rails-sample.&lt;dokku.example.com&gt;<\/tt>&nbsp;for example.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">CentOS firewall blocks access to the HTTP port by default. Use the command below to enable the web service.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo firewall-cmd --permanent --add-service http\nsudo firewall-cmd --reload<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">You can then click the link in your terminal or browse to the address to test the application.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/upcloud.com\/media\/ruby-rails-sample-1.png\" alt=\"Ruby rails sample\" class=\"wp-image-6224\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Congratulations, when you get a hello page similar to the example above, you have successfully deployed your first app on Dokku.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusions<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Deploying a single host scalable Platform-as-a-Service in the cloud could not be much easier than with Dokku. One of the strengths of Dokku is the extent of already <a href=\"https:\/\/dokku.com\/docs\/community\/plugins\/\" target=\"_blank\" rel=\"noreferrer noopener\">available plugins<\/a>, but also that Dokku is making it possible to write your own in any language. Sharing your plugins online and extending those already available will help the platform to grow. Dokku\u2019s simple core is intended to be easy to hack and expand upon with features you need.<\/p>\n","protected":false},"author":3,"featured_media":27358,"comment_status":"open","ping_status":"closed","template":"","community-category":[223],"class_list":["post-2305","tutorial","type-tutorial","status-publish","has-post-thumbnail","hentry"],"acf":[],"_links":{"self":[{"href":"https:\/\/upcloud.com\/global\/wp-json\/wp\/v2\/tutorial\/2305","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/upcloud.com\/global\/wp-json\/wp\/v2\/tutorial"}],"about":[{"href":"https:\/\/upcloud.com\/global\/wp-json\/wp\/v2\/types\/tutorial"}],"author":[{"embeddable":true,"href":"https:\/\/upcloud.com\/global\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/upcloud.com\/global\/wp-json\/wp\/v2\/comments?post=2305"}],"version-history":[{"count":0,"href":"https:\/\/upcloud.com\/global\/wp-json\/wp\/v2\/tutorial\/2305\/revisions"}],"wp:attachment":[{"href":"https:\/\/upcloud.com\/global\/wp-json\/wp\/v2\/media?parent=2305"}],"wp:term":[{"taxonomy":"community-category","embeddable":true,"href":"https:\/\/upcloud.com\/global\/wp-json\/wp\/v2\/community-category?post=2305"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}