My dockerfile


FROM ubuntu:latest
MAINTAINER Haifeng Wang <hfwang att>


# Postgresql DB
RUN echo “deb `lsb_release -cs`-pgdg main” >> /etc/apt/sources.list.d/pgdg.list
RUN apt-get install -y wget
RUN wget -q -O – | sudo apt-key add –

RUN apt-get update
RUN apt-get upgrade -y

RUN apt-get install -y postgresql postgresql-contrib
RUN /etc/init.d/postgresql start
RUN mkdir -p /opt/postgresql/tongueval
RUN chown postgres:postgres /opt/postgresql/tongueval
USER postgres
RUN psql –command “CREATE TABLESPACE tongueval LOCATION ‘/opt/postgres/tongueval’;”
RUN psql –command “CREATE USER tongueval WITH PASSWORD ‘password’;”
RUN psql –command “CREATE DATABASE tongueval OWNER=tongueval template=template0 encoding=’UTF-8′ TABLESPACE=tongueval;”
RUN echo “host all all md5” >> /etc/postgresql/9.5/main/pg_hba.conf

Then I run docker build for my image, “docker build .”

Step 12 : USER postgres

—> Using cache

—> 3dd84f680f22

Step 13 : RUN psql –command “CREATE TABLESPACE tongueval LOCATION ‘/opt/postgres/tongueval’;”

—> Running in 3b90f5e2499e

psql: could not connect to server: Connection refused

Is the server running locally and accepting

connections on Unix domain socket “/var/run/postgresql/.s.PGSQL.5432”?

The command ‘/bin/sh -c psql –command “CREATE TABLESPACE tongueval LOCATION ‘/opt/postgres/tongueval’;”‘ returned a non-zero code: 2

To try the SQL script failed during the build process,

docker run -ti –rm 3dd84f680f22