美文网首页我爱编程
Dokku部署腾讯云ubuntu 16.04简介

Dokku部署腾讯云ubuntu 16.04简介

作者: 马可菠萝_1d13 | 来源:发表于2018-05-18 15:45 被阅读0次

Deploying to Dokku

部署到Dokku

Deploy tutorial

部署教程

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配置了一个用户(以上),就可用git push命令来部署应用。下面用实例来介绍一下Dokku开发,你可以使用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主机上创建应用。你需要ssh登录主机运行以下命令。

shell

#on the Dokku host

dokku apps:create ruby-rails-sample

Create the backing services

创建后台服务

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:

当你新建一个app时候,Dokku默认不提供任何数据存储,如Mysql和Postgres。你需要安装插件来解决数据库。幸运的是Dokku官方插件可以应付普通的数据存储。我们的例子app需要一个Postgres的服务。

shell

#on the Dokku host在Dokku主机上

#install the postgres plugin安装postgres插件

#plugin installation requires root, hence the user change需要root权限

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

#create a postgres service with the name rails-database创建服务并命名

dokku postgres:create rails-database

Each service may take a few moments to create.

每个服务需要一点时间来创建。

Linking backing services to applications

将服务链接到应用上

Once the service creation is complete, set the POSTGRES_URL environment variable by linking the service.

一旦服务创建完成,通过链接服务来设置POSTGRES_URL环境变量

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.

你可以链接一个服务到多个应用上,或者使用每个应用都使用一个服务。

Deploy the app

部署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.

现在你可以部署ruby-rails-sample应用到你的Dokku服务器。你所做的只是为app指定一个remote名。应用将在Dokku服务器上自动创建。

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语法如上所示。你需要为upstream加ssh://前缀诸如,ssh://dokku@dokku.me:ruby-rails-sample。更多细节请查看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.

当部署完毕,以上应用的URL的会显示出来

Dokku supports deploying applications via Heroku buildpacks with Herokuish or using a project's dockerfile.

Dokku通过Heroku buildpacks与Herokuish或者使用一个项目dockerfile来部署应用。

Skipping deployment

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一个容器,你可以通过设置$DOKKU_SKIP_DEPLOY=true来跳过部署阶段。

shell

#on the Dokku host

dokku config:set ruby-rails-sample DOKKU_SKIP_DEPLOY=true

Re-Deploying / restarting

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.

更多信息请看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.

Deploying to subdomains

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后,会自动打开一个dokku-installer.py的程序

开启在80端口上,绑定一个ssh-key,但是这个页面的jquery是在google的cdn上,貌似被墙了。

需要去/usr/share/dokku/contrib/dokku-installer.py修改一下script

改成https://cdn.bootcss.com/jquery/1.10.2/jquery.min.js即可

也可以手动关闭服务sudo service dokku-installer stop

然后手动更新ssh-key。

相关文章

网友评论

    本文标题:Dokku部署腾讯云ubuntu 16.04简介

    本文链接:https://www.haomeiwen.com/subject/kvgjhftx.html