Add logging to PostgresQL on Docker

Normally, in docker-compose.yml I would just configure a database like this:

  image: postgres:9.4

However, to customise the image, we use our own Dockerfile:

FROM postgres:9.4
ADD /docker-entrypoint-initdb.d/

The contents of

perl -pi -e "s/#log_statement = 'none'/log_statement = 'all'/g" \

And docker-compose.yml now becomes:

  build: location/of/new/docker/file

Link your app, launch the stack, and start seeing log statements on STDIN:

db_1         | LOG:  statement: BEGIN
db_1         | LOG:  statement: SELECT etc etc