Deploying Dokku Lightweight Open-Source PaaS on Ubuntu 24.04
Deploying Dokku Lightweight Open-Source PaaS on Ubuntu 24.04
在 Ubuntu 24.04 上部署轻量级开源 PaaS:Dokku
Dokku is an open-source, Heroku-like Platform-as-a-Service that lets you git push apps and have them built and deployed automatically. This guide deploys Dokku on Ubuntu 24.04 with Docker Compose, registers an SSH key, deploys a sample Ruby app, and switches the proxy to Traefik for automatic HTTPS. By the end, you’ll have a Dokku PaaS running an app at your domain over HTTPS.
Dokku 是一个开源的、类似 Heroku 的平台即服务(PaaS),允许你通过 git push 自动构建和部署应用程序。本指南将介绍如何在 Ubuntu 24.04 上使用 Docker Compose 部署 Dokku,注册 SSH 密钥,部署一个示例 Ruby 应用,并将代理切换为 Traefik 以实现自动 HTTPS。完成后,你将拥有一个运行在你的域名下并支持 HTTPS 的 Dokku PaaS 环境。
Set Up the Directory Structure
设置目录结构
- Create the project directory:
- 创建项目目录:
$ mkdir -p ~/dokku/data
$ cd ~/dokku
- Create the environment file:
- 创建环境变量文件:
$ nano .env
DOKKU_HOSTNAME=dokku.example.com
DOKKU_VERSION=0.37.6
Deploy with Docker Compose
使用 Docker Compose 部署
- Add your user to the Docker group:
- 将你的用户添加到 Docker 组:
$ sudo usermod -aG docker $USER
$ newgrp docker
- Create the Docker Compose manifest:
- 创建 Docker Compose 清单文件:
$ nano docker-compose.yml
services:
dokku:
image: dokku/dokku:${DOKKU_VERSION}
container_name: dokku
network_mode: bridge
ports:
- "3022:22"
volumes:
- "./data:/mnt/dokku"
- "/var/run/docker.sock:/var/run/docker.sock"
environment:
DOKKU_HOSTNAME: ${DOKKU_HOSTNAME}
DOKKU_HOST_ROOT: /var/lib/dokku/home/dokku
DOKKU_LIB_HOST_ROOT: /var/lib/dokku/var/lib/dokku
restart: unless-stopped
- Start the service:
- 启动服务:
$ docker compose up -d
$ docker compose ps
Register an SSH Key
注册 SSH 密钥
- Generate a key on your workstation:
- 在你的工作站上生成密钥:
$ ssh-keygen -t ed25519 -f ~/.ssh/id_ed25519 -C "dokku"
$ cat ~/.ssh/id_ed25519.pub
- Register the public key with Dokku:
- 将公钥注册到 Dokku:
$ echo "YOUR_SSH_KEY" | docker compose exec -T dokku dokku ssh-keys:add admin
$ docker compose exec -it dokku dokku ssh-keys:list
- Add a Dokku entry to your SSH config:
- 在你的 SSH 配置中添加 Dokku 条目:
$ nano ~/.ssh/config
Host dokku-server
HostName YOUR_SERVER_IP
User dokku
Port 3022
IdentityFile ~/.ssh/id_ed25519
Deploy a Sample App
部署示例应用
- Create the app on the server:
- 在服务器上创建应用:
$ ssh dokku-server apps:create ruby-getting-started
$ ssh dokku-server apps:list
- Clone the sample app locally and push it:
- 在本地克隆示例应用并推送:
$ git clone https://github.com/heroku/ruby-getting-started
$ cd ruby-getting-started
$ git remote add dokku dokku-server:ruby-getting-started
$ git push dokku main
Switch to Traefik with Let’s Encrypt
使用 Let’s Encrypt 切换到 Traefik
- Stop the default Nginx proxy and enable Traefik:
- 停止默认的 Nginx 代理并启用 Traefik:
$ ssh dokku-server nginx:stop
$ ssh dokku-server proxy:set --global traefik
$ ssh dokku-server traefik:set --global letsencrypt-email username@example.com
- Assign the domain and start Traefik:
- 分配域名并启动 Traefik:
$ ssh dokku-server domains:set ruby-getting-started dokku.example.com
$ ssh dokku-server traefik:start
$ ssh dokku-server ps:rebuild ruby-getting-started
Open https://dokku.example.com to confirm the app is served over HTTPS.
打开 https://dokku.example.com 以确认应用已通过 HTTPS 提供服务。
Manage Environment Variables
管理环境变量
$ ssh dokku-server config:set ruby-getting-started SECRET_KEY=your-secret-value
$ ssh dokku-server config:set ruby-getting-started DB_HOST=localhost DB_USER=admin DB_PASS=secret
$ ssh dokku-server config:show ruby-getting-started
$ ssh dokku-server config:unset ruby-getting-started SECRET_KEY
Next Steps
后续步骤
Dokku is running with an app deployed via git push and Traefik handling HTTPS. From here you can:
Dokku 现已运行,应用通过 git push 部署,并由 Traefik 处理 HTTPS。接下来你可以:
- Install plugins for PostgreSQL, MySQL, Redis, and other backing services
- 安装 PostgreSQL、MySQL、Redis 及其他后端服务的插件
- Configure zero-downtime deploys with checks and procfile health endpoints
- 通过检查和 Procfile 健康检查端点配置零停机部署
- Deploy multiple apps under subdomains by repeating the apps:create flow
- 通过重复
apps:create流程在子域名下部署多个应用
For the full guide with additional tips, visit the original article on Vultr Docs. 如需获取包含更多技巧的完整指南,请访问 Vultr Docs 上的原始文章。