Monday, August 12, 2019

Docker file for build example postgresql database

Here is the docker file
FROM library/postgres:9.5
# echo version
RUN postgres --version

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

#Set 'postgres' account's password
ENV POSTGRES_PASSWORD=postgres

EXPOSE 5432

CMD ["postgres"]

Below is the file init.sql where we can defined script to init data
CREATE USER admin WITH PASSWORD 'admin' SUPERUSER CREATEDB CREATEROLE;

CREATE DATABASE myDB;
GRANT ALL PRIVILEGES ON DATABASE myDB TO admin;
GRANT ALL PRIVILEGES ON DATABASE myDB TO postgres;

No comments:

Post a Comment