Docker postgres & populate data

Build custom image

Dockerfile

FROM postgres:9.6.5

ENV POSTGRES_USER docker
ENV POSTGRES_PASSWORD docker
ENV POSTGRES_DB docker

ADD init.sql /docker-entrypoint-initdb.d/

init.sql

-- CREATE USER docker;
-- CREATE DATABASE docker;
-- GRANT ALL PRIVILEGES ON DATABASE docker TO docker;

CREATE TABLE post (
  id serial NOT NULL,
  name character varying NOT NULL,
  CONSTRAINT post_pk PRIMARY KEY (id)
) WITH (
OIDS=FALSE
);
ALTER TABLE post OWNER TO docker;


CREATE TABLE category (
  id serial NOT NULL,
  name character varying NOT NULL,
  CONSTRAINT category_pk PRIMARY KEY (id)
) WITH (
OIDS=FALSE
);
ALTER TABLE category OWNER TO docker;

Build

docker build -t szalek/postgres_test:1.1 .

Run

docker run -p 5400:5432 -d -i szalek/postgres_test:1.1