利用 Dokku 建構快速步署應用程式

Dokku

讓你建置類似像 Heroku 的服務,可至官方 Github了解更多資訊。

Installation

1
2
3
4
5
6
7
# wget https://raw.github.com/progrium/dokku/v0.3.17/bootstrap.sh
# sudo DOKKU_TAG=v0.3.17 bash bootstrap.sh

# installs dokku via apt-get
wget -qO- https://raw.github.com/progrium/dokku/v0.3.17/bootstrap.sh | sudo DOKKU_TAG=v0.3.17 bash

# Go to your server's IP and follow the web installer

Dokku-alt

基於 Dokku 發展的套包,集合了一些常用的 Plugins,像是 MariaDB, Redis, ACL … 等。

Installation

1
sudo bash -c "$(curl -fsSL https://raw.githubusercontent.com/dokku-alt/dokku-alt/master/bootstrap.sh)"

指定 buildpack

1
dokku config:set <app> BUILDPACK_URL=https://github.com/heroku/heroku-buildpack-php

BUILDPACK URL 參考:

1
2
3
4
5
6
7
8
9
10
Ruby    https://github.com/heroku/heroku-buildpack-ruby
Node.js https://github.com/heroku/heroku-buildpack-nodejs
Clojure https://github.com/heroku/heroku-buildpack-clojure
Python https://github.com/heroku/heroku-buildpack-python
Java https://github.com/heroku/heroku-buildpack-java
Gradle https://github.com/heroku/heroku-buildpack-gradle
Grails https://github.com/heroku/heroku-buildpack-grails
Scala https://github.com/heroku/heroku-buildpack-scala
Play https://github.com/heroku/heroku-buildpack-play
PHP https://github.com/heroku/heroku-buildpack-php

Multi-Buildpack

建立 .buildpacks 檔案並指定不同的 buildpack

例如:

1
2
https://github.com/heroku/heroku-buildpack-nodejs
https://github.com/heroku/heroku-buildpack-php

Example

SSH 進 docker container

1
sudo docker exec -i -t <id> bash

Clean up docker

Kill all running containers

1
sudo docker kill $(sudo docker ps -q)

Delete all stopped containers (including data-only containers)

1
sudo docker rm $(sudo docker ps -a -q)

Delete all ‘untagged/dangling’ () images

1
sudo docker rmi $(sudo docker images -q -f dangling=true)

Delete ALL images

1
sudo docker rmi -f $(sudo docker images -q)

已知問題

若與 CSF firewall 搭配使用,重開機後會造成 deployment building 失敗,應該是因為阻擋了 forward 的通道…

所以改用 ufw 代替,需修改 /etc/default/ufw 檔案

DEFAULT_FORWARD_POLICY 設為 ACCEPT

參考資料