title: Cannot connect to postgres server in docker
body: <p>I started a postgresql server in docker and exposed the 5432 port by <code>sudo docker run -it -p 5432:5432 9c421f1a239c bash</code> and start the postgres server manually inside the docker container, but cannot connect to it with command: <code>psql -h  172.17.0.63 -U venti</code>. <code>172.17.0.63</code> is a right IP, and venti is my pg username. But get error:</p>
  
  <pre><code>psql: could not connect to server: Connection refused
      Is the server running on host "172.17.0.63" and accepting
      TCP/IP connections on port 5432?
  </code></pre>
  
  <p>My pg_hba.conf looks like this:</p>
  
  <pre><code>local   all             postgres                                peer
  host all all 0.0.0.0/0 trust
  local all all trust
  </code></pre>
  
  <p>Connecting to pg server inside container works successfully.</p>
  
  <p>Dockerfile:</p>
  
  <pre><code>FROM ubuntu:12.04
  RUN apt-get update
  
  RUN apt-get install -y gcc libc-dev-bin libc6 libc6-dev libssl-dev libkrb5-dev comerr-dev
  
  RUN apt-get install -y postgresql-common libpq-dev postgresql-9.1-postgis --fix-missing
  RUN apt-get install -y postgresql postgresql-client
  
  USER postgres
  
  ENV PGDATA /etc/postgresql/9.1/main
  ENV LOGDIR  /etc/postgresql/9.1/main/postgresql.log
  
  WORKDIR /usr/lib/postgresql/9.1/bin
  USER root
  RUN apt-get install -y vim
  USER postgres
  RUN sed -e '90d' -i /etc/postgresql/9.1/main/pg_hba.conf
  RUN sed -e '91d' -i /etc/postgresql/9.1/main/pg_hba.conf
  
  RUN echo "host all all 0.0.0.0/0 trust" &gt;&gt; '/etc/postgresql/9.1/main/pg_hba.conf'
  RUN echo "local all all trust" &gt;&gt; '/etc/postgresql/9.1/main/pg_hba.conf'
  
  RUN ./pg_ctl start &amp;&amp; sleep 8 &amp;&amp; ./createdb pg &amp;&amp; ./createdb bloodstone \
      &amp;&amp; createuser -Upostgres -s venti \
      &amp;&amp; createdb -Uventi -Oventi venti
  
  # ENTRYPOINT ./pg_ctl start &amp;&amp; bash -c "while true; do echo "" &gt; /dev/null; sleep 1; done" 
  
  VOLUME $PGDATA
  EXPOSE 5432
  </code></pre>