Can I make initdb quiet?

A #postgresql user today asked:

noob question - trying to write a Dockerfile that runs postgres... how do I get the effect of a non-interactive `service postgresql initdb` call?

While several other community members provided the truthful but not helpful answer of, "Just throw Docker in the Trash", I worked out the following hack/trick/snipe hunt. The answer is, you can't. You have to call initdb directly. This took a few tries because PostgreSQL does not ship -q (quiet) flag with initdb. It will always make noise even when you don't want it to. However, if you call initdb directly, pass a few flags that have nothing to do with actually being quiet and redirect STDERR then you are golden. For example:
/usr/lib/postgresql/9.5/bin/initdb data -A md5 --pwfile=pwfile 2>&1 > /dev/null

The above says:

  1. Initialize a new data directory called data.
  2. Use the auth method of md5 to start
  3. Tell initdb to get the password for md5 from the password file of pwfile
  4. Redirect STDERR to STDOUT and then write that output to /dev/null

This will produce zero output on execution. You could still have for a RETVAL to see if it suceeded or change /dev/null to a log file.