How to use this image

start a postgres instance

This image includes EXPOSE 5432 (the postgres port), so standard container linking will make it automatically available to the linked containers. The default postgres user and database are created in the entrypoint with initdb.

... or via psql

Environment Variables

This image implements the same environment variables as the official PostgreSQL image:

POSTGRES_PASSWORD - sets the superuser password for PostgreSQL. The default superuser is defined by the POSTGRES_USER environment variable. In the above example, it is being set to "mysecretpassword".

POSTGRES_USER - used in conjunction with POSTGRES_PASSWORD to set a user and its password. This variable will create the specified user with superuser power and a database with the same name. If it is not specified, then the default user of postgres will be used.

There are also three variables that control the supervisord instance to allowstarting and stopping the server for testing purposes.

SUPERVISOR_XMLRPC_PORT: TCP port number used for XML-RPC. If set, thisenables XML-RPC on the nominated port. The suggested port for this is 9001as per supervisord documentation; this is EXPOSEd to other containers.

SUPERVISOR_XMLRPC_USERNAME: If set, this defines the username required forauthentication with XML-RPC. Otherwise, no authentication is required.

SUPERVISOR_XMLRPC_PASSWORD: If set, this defines the password required forauthentication with XML-RPC.

How to extend this image

With a Dockerfile

With a shell script in prestart-init.d

If you would like to do additional initialization before the database is started, add a *.sh script under /usr/local/etc/docker-postgres/prestart-init.d/. After the entrypoint calls initdb to create the user and database, it will source any *.sh script found in that directory to do further initialization before starting the service. The database is not running at this point. If you need to execute SQL commands as part of your initialization, the use of Postgres'' single user mode is recommended, but note that it comes with limitations.

With a shell script in poststart-init.d

In addition to the prestart hook above, this image provides a further init capability specifically for running SQL scripts against a full version of the database server. Add *.sh scripts under /usr/local/etc/docker-postgres/poststart-init.d/ and once the database is started these will be sourced and run with the postgres system user. Note that you can access POSTGRES_USER and POSTGRES_DB in these scripts to run commands against the specific database. An example of how to execute SQL against the running database:

Caveats

If there is no database when postgres starts in a container, then postgres will create the default database for you. While this is the expected behavior of postgres, this means that it will not accept incoming connections during that time. This may cause issues when using automation tools, such as docker-compose (or fig), that start several containers simultaneously.