title: PostgreSQL docker: "could not bind IPv6 socket: Cannot assign requested address"
body: <p><strong>EDIT 2: After a long time, solved! See answer below.</strong></p>
  
  <p>EDIT: I am sorry to say that the the problems went away "on their own" between yesterday and today, without me having done anything. Great non-deterministic lesson to learn here...
  Bonus fun: the "could not bind IPv6 socket" error still appears in the error logs, so this was probably not even the problem in the first place.</p>
  
  <p>I have a problem with a previously functioning docker PGSQL image. Until an uninspired rebuild yesterday ( :-D ), I've used this build successfully for the last 5+ months.</p>
  
  <p><strong>My system:</strong></p>
  
  <ul>
  <li>Ubuntu 17.04 64b</li>
  <li>PGSQL 9.6.4</li>
  <li>Docker version 17.11.0-ce, build 1caf76c</li>
  <li>I am mapping host port 5433 to container port 5432</li>
  </ul>
  
  <p><strong>The problem</strong> (snippet from the PGSQL logs):</p>
  
  <blockquote>
    <p>...</p>
    
    <p>LOG:  could not bind IPv6 socket: Cannot assign requested address</p>
    
    <p>HINT:  Is another postmaster already running on port 5432? If not, wait a few seconds and retry.</p>
    
    <p>...</p>
  </blockquote>
  
  <p>This is what <strong>ss</strong> is telling me (when the container is running, obviously):</p>
  
  <pre><code>    $ docker exec -it db ss -atune
      Netid  State      Recv-Q Send-Q     Local Address:Port       Peer Address:Port 
      udp    ESTAB      0      0              127.0.0.1:45876         127.0.0.1:45876  uid:999 ino:147509 sk:00000001 &lt;-&gt;
      tcp    LISTEN     0      128            127.0.0.1:5432                  *:*      uid:999 ino:147500 sk:00000002 &lt;-&gt;
  </code></pre>
  
  <p>I've cleaned all docker containers / images, I've reinstalled docker, nothing helped. Who can possibly be using the 5432 port in the container?
  For that matter, am I reading this correctly, that PGSQL is complaining about the 5432 port being already used in the docker container?</p>
  
  <p>Even if you have no solution, a basic idea of how to proceed with debugging this would be a great help.</p>
  
  <p>EDIT:</p>
  
  <p><strong>postgres.docker file</strong></p>
  
  <pre><code>FROM postgres:9.6.4
  
  ADD bin/postgres-setup.sh /docker-entrypoint-initdb.d/postgres-setup.sh
  
  RUN chmod 755 /docker-entrypoint-initdb.d/postgres-setup.sh &amp;&amp; \
      apt-get update &amp;&amp; \
      apt-get install -y --no-install-recommends postgresql-plpython3-9.6 python3-pip postgresql-9.6-pldebugger &amp;&amp; \
      pip3 install pyexcel pyexcel-xls pyexcel-xlsx pyexcel-xlsxw
  </code></pre>