dokku-psql-single-container is a plugin for dokku that provides a Postgresql server in a single container for your applications.
It uses the official Postgresql docker image (version 9.3) by default but you can provide an alternative image.
This version is compatible with dokku 0.3.26+.
# dokku 0.3.26
$ git clone https://github.com/Flink/dokku-psql-single-container.git /var/lib/dokku/plugins/psql-sc
$ dokku plugins-install
# dokku 0.4+
$ dokku plugin:install https://github.com/Flink/dokku-psql-single-container.git
If you want to use an alternative image instead of the default postgres:9.3
one, you just have to set it in the global dokku config before
running dokku plugins-install
.
dokku config:set --global PSQL_SC_IMAGE=postgres:9.4
By default, this plugin stores its data in $DOKKU_ROOT/.psql-sc
. If you want
to store it elsewhere, you have to set the PSQL_SC_ROOT
in the global dokku
config. You should do it before running dokku plugins-install
. Note:
If you are using custom PSQL_SC_ROOT
directory, make sure it is writable by
dokku
user.
dokku config:set --global PSQL_SC_ROOT=/my/custom/path
By default, the container is not reachable from outside. The container can be
bound to an IP of your choice by setting PSQL_SC_BIND_IP
to an IP in the
global dokku config.
dokku config:set --global PSQL_SC_BIND_IP=0.0.0.0
$ dokku help
psql:admin_console Launch a postgresql console as admin user
psql:console <app> Launch a postgresql console for <app>
psql:create <app> Create a Postgresql database for <app>
psql:delete <app> Delete Postgresql database for <app>
psql:dump <app> > <filename.dump> Dump <app> database to PG dump format
psql:link <source> <target> Link <source> app DB to <target> app
psql:list List all databases
psql:restart Restart the Postgresql docker container
psql:restore <app> < <filename.*> Restore database to <app> from any non-plain-text format exported by pg_dump
psql:start Start the Postgresql docker container if it isn't running
psql:status Shows status of Postgresql
psql:stop Stop the Postgresql docker container
psql:unlink <app> Remove DB config for <app>
psql:url <app> Get DATABASE_URL for <app>
psql:version Output version of plugin
This plugin adds the following environment variables to your app automatically (they are available via dokku config
):
$ dokku psql:start # Server side
$ ssh dokku@server psql:start # Client side
$ dokku psql:stop # Server side
$ ssh dokku@server psql:stop # Client side
$ dokku psql:restart # Server side
$ ssh dokku@server psql:restart # Client side
$ dokku psql:create foo # Server side
$ ssh dokku@server psql:create foo # Client side
$ dokku psql:dump foo > filename.dump # Server side
$ dokku psql:restore foo < filename.dump # Server side
For plain-text format, you should do this instead:
$ dokku psql:console < dump.sql
$ dokku psql:dump foo | dokku psql:restore bar # Server side
$ dokku psql:link app_with_db target_app # Server side
$ dokku psql:unlink foo # Server side
If you inadvertently unlink an app owning a DB, there is a very easy way to recover the configuration vars:
$ dokku psql:link foo foo # Server side
When upgrading Dokku to a newer version, owner of /home/dokku/.psql-sc/data
will be changed to dokku
. It can causes errors with the container.
You’ll have to restore the previous owner by issuing the following command:
$ chown 999 -R /home/dokku/.psql-sc/data
This plugin is based originally on the one by Olivier Hardy.
This plugin is released under the MIT license. See the file LICENSE.