markdown 在数字海洋上运行Dokku的注意事项。
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了markdown 在数字海洋上运行Dokku的注意事项。相关的知识,希望对你有一定的参考价值。
My notes for Dokku on Digital Ocean.
These may be a bit outdated: Since I originally wrote them, I've reinstalled on a newer Dokku and may not have updated every section below.
## Commands
Install [dokku-cli](https://github.com/SebastianSzturo/dokku-cli) (`gem install dokku-cli`) for a more Heroku-like CLI experience (`dokku config:set FOO=bar`).
# List/run commands when not on Dokku server (assuming a "henroku" ~/.ssh/config alias)
ssh henroku dokku
ssh henroku dokku config:get my-app
# Access the server, list commands, run command
ssh henroku
dokku
dokku config:get my-app
# See memory usage (from: https://github.com/progrium/dokku/issues/1297)
docker ps -q | xargs docker stats
# Compare to the names you see here
docker ps
# See server stats (memory, disk usage, load) - same as shown on login
landscape-sysinfo
# Interesting dirs
cd /var/lib/dokku/plugins # plugins
cd ~dokku # apps
### Adding a new app
git remote add dokku dokku@henroku.nyh.name:my-app
git push dokku
ssh henroku dokku domains:add my-app my-app.nyh.name # and configure DNS
# DB?
ssh henroku dokku psql:create my-app
# memcache?
ssh henroku dokku memcached:create my-app # MEMCACHE_SERVERS env will be set
### Working with an app
# See logs
ssh henroku dokku logs my-app -t
# Conf
ssh henroku dokku config:get my-app
ssh henroku dokku config:set my-app KEY1=val KEY2=val
### Removing a plugin
cd /var/lib/dokku/plugins
rm -rf the-plugin
# List containers, remove the ones from the plugin
ssh henroku
sudo docker ps -a
docker rm <the id>
# List images, remove the ones from the plugin
docker images
docker rmi <the id>
* [How to uninstall a Dokku plugin](https://github.com/progrium/dokku/issues/519)
## Setup
Use Digital Ocean's "Ubuntu with Dokku" image.
[Create a swapfile](http://dev.housetrip.com/2014/07/06/deploy-rails-and-postgresql-app-to-dokku/) to avoid out-of-memory errors during build/deploy (I got those sometimes even with a 1 GB RAM image):
```
ssh henroku
dd if=/dev/zero of=/swapfile bs=1024 count=1024000
mkswap /swapfile
swapon /swapfile
```
Change the default root password to avoid [later issues with crontab not working](http://askubuntu.com/a/846048/443378):
```
sudo -u root passwd
```
Follow the instructions, specifying a new password as prompted, and store it in e.g. 1Password.
## DNS
It's convenient to set up wildcard DNS so e.g. `*.henroku.nyh.name` points to this server.
With LoopiaDNS, you need to add a CNAME for sub-subdomain wildcards (e.g. `*.henroku.nyh.name` pointing to `henroku.nyh.name`).
## Plugins
### memcached
https://github.com/Flink/dokku-memcached-plugin
This fork seems to be the most up to date, with nice features like autostart on server reboot.
cd /var/lib/dokku/plugins
git clone git@github.com:Flink/dokku-memcached-plugin.git
git clone https://github.com/rlaneve/dokku-link.git link # dependency
dokku plugins-install
### PostgreSQL
<https://github.com/Flink/dokku-psql-single-container>
Before you install, see [the section on getting a newer version of Postgres](https://github.com/Flink/dokku-psql-single-container#providing-an-alternative-docker-image-for-postgresql). At the time of writing, 9.4 has some cool new features over the default 9.3.
After install, run: `dokku psql:start`
(Got errors from Kloadut/dokku-pg-plugin, and it seems unmaintained.)
## DB backups
Put one of these scripts ([for dokku-postgres](https://gist.github.com/henrik/5ebff4ba7d18df85144520e20210a178) or [for dokku-psql-single-container](https://gist.github.com/henrik/1043fecdd0937034cd62)) in `/root/database_backups.sh`, run `chmod +x /root/database_backups.sh`.
Then add something like this to crontab:
``` cron
# m h dom mon dow command
0 0 * * * /root/database_backups.sh
```
You will get daily backups in `/var/backups/postgres`. The script keeps a few days and then removes too old ones. Digital Ocean's infrequent server backups will include these dumps.
I recommend also [adding a healthcheck](https://healthchecks.io/docs/#crontab) to the cron job.
## Static sites alongside Dokku
See [this blog post](https://thepugautomatic.com/2016/01/static-sites-alongside-dokku-on-digital-ocean/).
## Resources
* [Dokku docs](http://progrium.viewdocs.io/dokku/installation/)
* [Dokku plugins](http://progrium.viewdocs.io/dokku/plugins/)
* [Copying a Heroku DB to dokku-psql-single-container](https://gist.github.com/henrik/e6817dd10d9c9a36c22a)
以上是关于markdown 在数字海洋上运行Dokku的注意事项。的主要内容,如果未能解决你的问题,请参考以下文章