How to Deploy Dokku on Ubuntu 16.04

本文涉及的产品
PolarSearch,搜索节点 4核8GB
云数据库 PolarDB MySQL 版,列存表分析加速 8核16GB
PolarDB Agent Express,2核4GB
简介: Dokku is an extensible, lightweight, open source Platform as a Service (PaaS) that runs on your server, such as Alibaba Cloud Elastic Compute Service (ECS).

0213_Distributed_messaging_engine_under_a_peak_of_terabytes_of_data_Part_1

By Nick Triller, Alibaba Cloud Tech Share Author

Dokku is an extensible, lightweight, open source Platform as a Service (PaaS) that runs on your server, such as Alibaba Cloud Elastic Compute Service (ECS). Dokku makes it easy to use ECS resources with Docker and allows you to focus on code instead of server management. Deploying your code is as easy as running a "git push". Using your own PaaS instead of third party platforms grants full control over your stack at lower costs.

This guide describes how to setup Dokku on Ubuntu 16.04 LTS and how to deploy your first Application to Dokku.

Prerequisites

Make sure you have an Alibaba Cloud account before you start. Sign up now to receive 300 $ in free credit. Create an ECS server or connect to an existing one with SSH to follow along. Your server should have at least 1GB of RAM to run Dokku. You will need Git and SSH on your computer. You will also need a SSH Key to configure authentication in Dokku. Optionally, you can use a domain. Using a domain allows mapping individual applications as subdomains. If an IP address is used to access the Dokku server, applications can only be mapped as sub paths.

Setup Dokku

The first step is setting the hostname of your server. Run 'hostname <hostname>' to set the hostname. We will use the hostname 'dokku.local' in this example. The hostname set with the 'hostname' command will only be used until the next reboot. After a reboot, the hostname will be read from the file '/etc/hostname'. Change the hostname in the Alibaba Cloud Console or open '/etc/hostname' directly with a text editor of your choice and replace the hostname.

Verify the hostname was set by running 'hostname' without any arguments. The output should be the hostname you set previously with the hostname command. It must match the hostname that was entered into '/etc/hostname'.

The file '/etc/hosts' is used to map hostnames to IP addresses. Debian-based operating systems use the IP 127.0.1.1 as the hostname IP. Open '/etc/hosts' with a text editor and add a line that maps the hostname IP address to your hostname. Dokku can't be installed without this mapping.

127.0.0.1       localhost
127.0.1.1 dokku.local

Run 'ping dokku.local' to verify the mapping works as expected.

# ping dokku.local
PING dokku.local (174.44.44.44) 56(84) bytes of data.
64 bytes from dokku.local (174.44.44.44): icmp_seq=1 ttl=64 time=0.016 ms

Now Dokku can be installed. Download the setup script from Dokku's GitHub repository with 'wget'.

# wget https://raw.githubusercontent.com/dokku/dokku/master/bootstrap.sh

Next, run the setup script with bash. You have to provide the Dokku version you want to install with the environment variable DOKKU_TAG.

# sudo DOKKU_TAG=v0.10.5 bash bootstrap.sh

The script checks if all prerequisites are fulfilled, creates a Linux user named 'dokku', installs Dokku and its dependencies (e.g. Docker and Nginx) etc.

The next step is opening the Dokku web installer. It is currently unavailable on CentOS. Use the Dokku CLI Tool to configure SSH keys and virtualhosts on CentOS. Port 80 of the ECS instance has to be exposed to allow access to the web installer. Open the Elastic Compute Section in the Alibaba Cloud Console. Choose your ECS instance and navigate to the 'Security Group' settings. Click on 'Configure Rules' on the relevant Security Group. Use the 'Quickly Create Rules' button to allow access on port 80 from all IPs.

firewall
Access the public IP address of your server to continue the setup with the Dokku web installer. You can find the public IP address in the Alibaba Cloud Console.
WARNING: If you don’t complete the web setup, anyone who finds the setup page can insert their SSH key, even if you configure the SSH key with the Dokku CLI Tool. The SSH key is used to deploy applications to Dokku.

Copy and paste the SSH public key you want to use for Dokku deployments into the intended field. Enter your server's public IP address or a domain name you own into the 'Hostname' field. If you use an IP address, deployed applications will be available on sub paths, e.g. http://47.333.333.333/myapp. If a domain is used, deployed applications can be made available on either sub paths or on subdomains, e.g. http://myapp.example.com. Tick the 'Use virtualhost naming for apps' checkbox if you want to mount applications as subdomains. In any case, make sure to configure your Domain's DNS settings if you use a domain. The domain has to point to point Dokku server. For example, create an A record with the public IP address of your server. Press 'Finish Setup' to save the Dokku settings.

dokku_web_installer

Congratulations! You have successfully setup your Dokku server.

How to deploy an application to Dokku

http://dokku.viewdocs.io/dokku/deployment/application-deployment/

You will learn how to deploy an application to Dokku next. First, clone a sample app project with Git on your computer:

git clone https://github.com/heroku/ruby-rails-sample.git

You will find the sample app code in a directory named "ruby-rails-sample" in your current working directory.

Next, we will take a look at the sample application repository. The only Dokku-specific file in the repository is the file 'Procfile'. Otherwise, the project is a standard ruby on rails project. These are the contents of the Procfile:

web: bundle exec puma -C config/puma.rb

'web' is the process type. 'web' processes are automatically scaled to 1 on the initial application deployment. The command after the double colon specifies the command that is used to start the application.

The goal is to deploy this sample application on the Dokku server. Before we can do so, we will have to configure the app and the backing services in Dokku.

SSH into your server. Dokku provides a command line tool with the same name. Dokku can be extended with plugins. You can find a list of plugins here. Some notable official plugins include the Elasticsearch, Grafana, MariaDB, RabbitMQ, Redis, Let's Encrypt and HTTP Auth plugins. Of course, you can implement your own plugins, too. The sample application needs a PostgreSQL database. Run the following command on your server to install the Dokku PostgreSQL plugin from GitHub. Make sure to install plugins as a root user (or with sudo):

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

Use the command 'dokku plugin:list' to verify the PostgreSQL plugin was installed successfully.

# dokku plugin:list
plugn: 0.3.0
[…]
nginx-vhosts 0.10.5 enabled dokku core nginx-vhosts plugin
plugin 0.10.5 enabled dokku core plugin plugin
postgres 1.0.0 enabled dokku postgres service plugin
proxy 0.10.5 enabled dokku core proxy plugin
[…]

We will create a PostgreSQL database instance with the name 'rails-database' with Dokku next. The database will be created as a Docker container. Therefore, the PostgreSQL container will be listed if you run 'docker ps' after you create the PostgreSQL database instance.

dokku postgres:create rails-database

Run the following command to create the sample application in Dokku:

dokku apps:create ruby-rails-sample

Verify the application was created by running 'dokku ps:report'. The application is not deployed or running yet.

root@dokku:~# dokku ps:report
=====>; ruby-rails-sample process information
Processes: 0
Deployed: false
Running: false
Restore: true
Restart policy: on-failure:10

The PostgreSQL database instance and the application are isolated. We have to link them together to allow the application to access the database instance. Linking the PostgreSQL service with the application sets the environment variable 'POSTGRES_URL' to the appropriate value once the sample application is deployed. Services can be shared between applications, too.

dokku postgres:link rails-database ruby-rails-sample

We are ready to deploy the application. Navigate to the sample code repository on your computer. Add the Dokku server as a remote to the sample code Git repository. Make sure to use the 'dokku' user as demonstrated below. Replace with your domain name or the server's public IP address:

git remote add dokku dokku@:ruby-rails-sample

Run 'git remote' to verify the remote was added successfully.

# git remote
dokku
origin

The SSH key that was provided in the Dokku web installer is used to authenticate with the Dokku server. The SSH program on your computer needs to be configured to use the appropriate SSH keys when you push code with Git to the Dokku server. Create a file with the name 'config' in the directory '~/.ssh'. The '~' denotes the home directory. On windows, it might be 'C:Users&lt;Username>'. The config file maps hosts to SSH keys that should be used when you connect to the host. The private part of the SSH key is named 'id_rsa' in this example. The public part should have the same name with '.pub' appended.

Host 47.333.333.333
User dokku
HostName 47.333.333.333
IdentityFile ~/.ssh/id_rsa

We are ready to deploy the application. The next command will push the master branch of the sample application's repository to Dokku with SSH.

# git push dokku master
Counting objects: 236, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (135/135), done.
Writing objects: 100% (236/236), 41.85 KiB | 10.46 MiB/s, done.
Total 236 (delta 85), reused 236 (delta 85)
remote: -----> Cleaning up...
remote: -----> Building ruby-rails-sample from herokuish...
[…]
remote: =====> Application deployed:
remote: http://ruby-rails-sample.example.com

If a domain is used and applications are mounted as subdomains, you might need to configure your DNS settings to access the deployed application. For example, add an A-Record with the host set to the subdomain 'ruby-rails-sample' and point it to the public IP of the Dokku server. The subdomain corresponds to the application name. Alternatively, a wildcard entry can be used to point all subdomains to the Dokku server. Dokku will use Nginx to route requests to the appropriate applications. Updated DNS settings can take up to 48 hours to propagate.

Dokku will fetch all necessary dependencies, build the application from the source code and deploy it. So called buildpacks contain the logic that is necessary to fetch the dependencies and build the application for different programming languages and platforms. The sample application is built with the ruby-buildpack. Like plugins, you can create your own buildpacks, too.

Congratulations! The sample application is up and running on the Dokku server. Verify the application works by accessing it on 'ruby-rails-sample.<domain>' or '<domain or IP>/ruby-rails-sample', depending on the Dokku configuration. You should see a web page with the text 'Hello World'. Redeploying the application after source code changes are made is as simple as running 'git push dokku master'.

相关实践学习
使用PolarDB和ECS搭建门户网站
本场景主要介绍如何基于PolarDB和ECS实现搭建门户网站。
阿里云数据库产品家族及特性
阿里云智能数据库产品团队一直致力于不断健全产品体系,提升产品性能,打磨产品功能,从而帮助客户实现更加极致的弹性能力、具备更强的扩展能力、并利用云设施进一步降低企业成本。以云原生+分布式为核心技术抓手,打造以自研的在线事务型(OLTP)数据库Polar DB和在线分析型(OLAP)数据库Analytic DB为代表的新一代企业级云原生数据库产品体系, 结合NoSQL数据库、数据库生态工具、云原生智能化数据库管控平台,为阿里巴巴经济体以及各个行业的企业客户和开发者提供从公共云到混合云再到私有云的完整解决方案,提供基于云基础设施进行数据从处理、到存储、再到计算与分析的一体化解决方案。本节课带你了解阿里云数据库产品家族及特性。
目录
相关文章
|
监控 JavaScript 前端开发
|
JavaScript 前端开发 Linux
Hook神器—Frida安装
Hook神器—Frida安装
1082 0
|
2天前
|
云安全 人工智能 运维
阿里云SecOps Agent,全新安全跨产品执行体验
自然语言驱动 云安全中心/WAF/CFW/ 等多款安全产品联动
1583 2
|
2天前
|
机器学习/深度学习 人工智能 调度
🐴 HappyHorse 1.1 现已上线阿里云百炼!快来查收模型使用指南,现在调用享 6 折~
HappyHorse 1.1 是新一代视频生成大模型,全面升级动态表现力、角色一致性、指令遵循、视觉质感与音画协同能力。支持I2V/T2V/R2V三类生成,适配短剧、电商广告、品牌营销等场景,提供高质、流畅、可控的AI视频生产力。
487 2
🐴 HappyHorse 1.1 现已上线阿里云百炼!快来查收模型使用指南,现在调用享 6 折~
|
13天前
|
缓存 测试技术 API
Qwen 3.7 Plus 与 Max 实测:性价比与多模态能力差异解析(2026)
2026 年 6 月 1 日,阿里悄无声息地发布了 Qwen 3.7 Plus,距 Qwen 3.7 Max 上线刚好 11 天。同样的 1M 上下文,同样的 35 小时自治上限。但价格才是头条:Plus 是 0.40/M输入,Max是 2.50/M——便宜约 6 倍——并且还能看图、看视频。Vision Arena 上 Plus 已经排到 #16。所以这周真正值得讨论的问题不是”要不要为视觉能力买单”,而是”Max 凭什么用 6 倍价格换来 2 个百分点的 benchmark 领先”。
|
14天前
|
JavaScript 定位技术 API
CodeGraph 爆火:编程 Agent 需要的不是更多上下文,而是一张提前画好的代码地图
CodeGraph 是一款爆火的本地代码智能工具,通过 tree-sitter 解析 AST 构建结构化知识图谱(存于 SQLite),为编程 Agent 提前生成“代码地图”。它显著降低 Agent 在中大型项目中的探索成本——实测工具调用减少71%、Token 降57%、速度提升46%,支持19+语言及主流框架路由识别,完全离线、无需 API Key。
875 11
CodeGraph 爆火:编程 Agent 需要的不是更多上下文,而是一张提前画好的代码地图
|
2天前
|
数据采集 人工智能 搜索推荐
企业智能体的下半场,如何让智能体越用越聪明?
AgentLoop 正在邀测期,点击申请邀测资格。
192 124
|
14天前
|
人工智能 运维 JavaScript
阿里云Qoder CN(原通义灵码)全解析 产品形态、版本划分与技术适配说明
在AI辅助开发与智能办公工具持续普及的当下,阿里云旗下原通义灵码正式更名为Qoder CN,同时延伸出QoderWork CN、Qoder CN CLI、Qoder CN Mobile等多款配套产品,形成覆盖代码开发、日常办公、终端交互、移动端使用的完整工具矩阵。Qoder CN核心定位为AI智能编码助手,深度适配主流代码编辑器、集成开发环境以及终端场景;QoderWork CN则偏向桌面端综合办公辅助,二者面向不同使用场景,划分了多个版本档位,搭配差异化资源配额、功能权限与计费规则,同时兼容多款主流大模型。
943 8

热门文章

最新文章