Deploying to Dokku
部署到Dokku
部署教程
Once Dokku has been configured with at least one user, applications can be deployed via a?git push?command. To quickly see Dokku deployment in action, you can use the Heroku Ruby on Rails example app.
只要給Dokku配置了一個(gè)用戶(以上)佣蓉,就可用git push命令來(lái)部署應(yīng)用。下面用實(shí)例來(lái)介紹一下Dokku開發(fā),你可以使用Heroku的Ruby on Rails例子app塞赂。
以下代碼:
shell
#from your local machine
#SSH access to github must be enabled on this host
git clone git@github.com:heroku/ruby-rails-sample.git
Create the app
Create the application on the Dokku host. You will need to ssh onto the host to run this command.
在Dokku主機(jī)上創(chuàng)建應(yīng)用春叫。你需要ssh登錄主機(jī)運(yùn)行以下命令噪矛。
shell
#on the Dokku host
dokku apps:create ruby-rails-sample
創(chuàng)建后臺(tái)服務(wù)
When you create a new app, Dokku by default?does not?provide any datastores such as MySQL or PostgreSQL. You will need to install plugins to handle that, but fortunately?Dokku has official plugins?for common datastores. Our sample app requires a PostgreSQL service:
當(dāng)你新建一個(gè)app時(shí)候小渊,Dokku默認(rèn)不提供任何數(shù)據(jù)存儲(chǔ)放可,如Mysql和Postgres谒臼。你需要安裝插件來(lái)解決數(shù)據(jù)庫(kù)。幸運(yùn)的是Dokku官方插件可以應(yīng)付普通的數(shù)據(jù)存儲(chǔ)耀里。我們的例子app需要一個(gè)Postgres的服務(wù)蜈缤。
shell
#on the Dokku host在Dokku主機(jī)上
#install the postgres plugin安裝postgres插件
#plugin installation requires root, hence the user change需要root權(quán)限
sudo dokku plugin:install https://github.com/dokku/dokku-postgres.git
#create a postgres service with the name rails-database創(chuàng)建服務(wù)并命名
dokku postgres:create rails-database
Each service may take a few moments to create.
每個(gè)服務(wù)需要一點(diǎn)時(shí)間來(lái)創(chuàng)建。
Linking backing services to applications
將服務(wù)鏈接到應(yīng)用上
Once the service creation is complete, set the?POSTGRES_URL?environment variable by linking the service.
一旦服務(wù)創(chuàng)建完成冯挎,通過(guò)鏈接服務(wù)來(lái)設(shè)置POSTGRES_URL環(huán)境變量
shell
#on the Dokku host
#each official datastore offers a `link` method to link a service to any application
dokku postgres:link rails-database ruby-rails-sample
You can link a single service to multiple applications or use one service per application.
你可以鏈接一個(gè)服務(wù)到多個(gè)應(yīng)用上底哥,或者使用每個(gè)應(yīng)用都使用一個(gè)服務(wù)。
部署app
Now you can deploy the?ruby-rails-sample?app to your Dokku server. All you have to do is add a remote to name the app. Applications are created on-the-fly on the Dokku server.
現(xiàn)在你可以部署ruby-rails-sample應(yīng)用到你的Dokku服務(wù)器房官。你所做的只是為app指定一個(gè)remote名趾徽。應(yīng)用將在Dokku服務(wù)器上自動(dòng)創(chuàng)建。
shell
#from your local machine
#the remote username *must* be dokku or pushes will fail
cd ruby-rails-sample
git remote add dokku dokku@dokku.me:ruby-rails-sample
git push dokku master
Note: Some tools may not support the short-upstream syntax referenced above, and you may need to prefix the upstream with the scheme?ssh://?like so:?ssh://dokku@dokku.me:ruby-rails-sample?Please see the?Git?documentation for more details.
注意:一些工具可能不支持short-upstream語(yǔ)法如上所示翰守。你需要為upstream加ssh://前綴諸如,ssh://dokku@dokku.me:ruby-rails-sample孵奶。更多細(xì)節(jié)請(qǐng)查看Git文檔。
Counting objects: 231, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (162/162), done.
Writing objects: 100% (231/231), 36.96 KiB | 0 bytes/s, done.
Total 231 (delta 93), reused 147 (delta 53)
-----> Cleaning up...
-----> Building ruby-rails-sample from herokuish...
-----> Adding BUILD_ENV to build environment...
-----> Ruby app detected
-----> Compiling Ruby/Rails
-----> Using Ruby version: ruby-2.2.1
-----> Installing dependencies using 1.9.7
? ? ? Running: bundle install --without development:test --path vendor/bundle --binstubs vendor/bundle/bin -j4 --deployment
? ? ? Fetching gem metadata from https://rubygems.org/...........
? ? ? Fetching version metadata from https://rubygems.org/...
? ? ? Fetching dependency metadata from https://rubygems.org/..
? ? ? Using rake 10.4.2
...
=====> Application deployed:
? ? ? http://ruby-rails-sample.dokku.me
When the deploy finishes, the application's URL will be shown as seen above.
當(dāng)部署完畢潦俺,以上應(yīng)用的URL的會(huì)顯示出來(lái)
Dokku supports deploying applications via?Heroku buildpacks?with?Herokuish?or using a project's?dockerfile.
Dokku通過(guò)Heroku buildpacks與Herokuish或者使用一個(gè)項(xiàng)目dockerfile來(lái)部署應(yīng)用。
If you only want to rebuild and tag a container, you can skip the deployment phase by setting?$DOKKU_SKIP_DEPLOY?to?true?by running:
如果你僅僅想重建和tag一個(gè)容器,你可以通過(guò)設(shè)置$DOKKU_SKIP_DEPLOY=true來(lái)跳過(guò)部署階段事示。
shell
#on the Dokku host
dokku config:set ruby-rails-sample DOKKU_SKIP_DEPLOY=true
If you need to re-deploy (or restart) your app:
如果你需要重新部署或者重啟app:
shell
#on the Dokku host
dokku ps:rebuild ruby-rails-sample
See the?process scaling documentation?for more information.
更多信息請(qǐng)看process scaling documentation
Deploying with private git submodules
Dokku uses git locally (i.e. not a docker image) to build its own copy of your app repo, including submodules. This is done as the?dokku?user. Therefore, in order to deploy private git submodules, you'll need to drop your deploy key in?/home/dokku/.ssh/?and potentially add github.com (or your VCS host key) into?/home/dokku/.ssh/known_hosts. The following test should help confirm you've done it correctly.
shell
#on the Dokku host
su - dokkussh-keyscan -t rsa github.com>>~/.ssh/known_hostsssh -T git@github.com
Note that if the buildpack or dockerfile build process require ssh key access for other reasons, the above may not always apply.
The name of remote repository is used as the name of application to be deployed, as for example above:
shell
#from your local machine
#the remote username *must* be dokku or pushes will fail
git remote add dokku dokku@dokku.me:ruby-rails-sample
git push dokku master
output
remote: -----> Application deployed:
remote:? ? ? ? http://ruby-rails-sample.dokku.me
You can also specify fully qualified names, say?app.dokku.me, as
shell
#from your local machine#the remote username *must* be dokku or pushes will failgit remote add dokku dokku@dokku.me:app.dokku.megit push dokku master
output
remote: -----> Application deployed:
remote:? ? ? ? http://app.dokku.me
This is in particular useful, then you want to deploy to root domain, as
shell
#from your local machine
#the remote username *must* be dokku or pushes will fail
git remote add dokku dokku@dokku.me:dokku.me
git push dokku master
output
... deployment ...
remote: -----> Application deployed:
remote:? ? ? ? http://dokku.me
#from your local machine
#SSH access to github must be enabled on this host
git clone git@github.com:heroku/ruby-rails-sample.git
安裝好dokku后早像,會(huì)自動(dòng)打開一個(gè)dokku-installer.py的程序
開啟在80端口上,綁定一個(gè)ssh-key肖爵,但是這個(gè)頁(yè)面的jquery是在google的cdn上卢鹦,貌似被墻了。
需要去/usr/share/dokku/contrib/dokku-installer.py修改一下script
改成https://cdn.bootcss.com/jquery/1.10.2/jquery.min.js即可
也可以手動(dòng)關(guān)閉服務(wù)sudo service dokku-installer stop
然后手動(dòng)更新ssh-key劝堪。