initdb.bin: invalid locale settings; check LANG and LC_* environment variables

On the docker image I was using every single locale was commented out in the /etc/locale.gen file. Meaning no locale was setup, which was causing this error.

Because I was scripting the build I ran the following two commands to fix the problem (you may want to manually edit /etc/locale.gen, if you want to avoid my nuclear option of overwriting the whole file)

echo en_US.UTF-8 UTF-8 > /etc/locale.gen
locale-gen en_US.UTF-8

The issue solved when i used the following commands

LC_ALL="en_US.UTF-8"
LC_CTYPE="en_US.UTF-8"

For Unix you have to be

export LC_ALL="en_US.UTF-8"
export LC_CTYPE="en_US.UTF-8"

On Ubuntu Ubuntu 19.04 (Disco Dingo) I had to set all these.

export LANGUAGE=en_US.UTF-8
export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8
locale-gen en_US.UTF-8
dpkg-reconfigure locales

The full doc is here.