PostgreSQL Docker installation how to setup initial database

I am pretty new to the docker technology and working on setting up the docker container with PostgreSQL setup, up and running as a service and default database created with initial schema created with the .sql file.

The docker file i am using is as below –

  • How can I use docker-compose locally after setting up a docker-machine host?
  • docker-compose doesn't build image from latest commit of git repository
  • how to tag image in docker registry v2
  • Windows server 2008 base image for docker
  • Node.js web application not running properly in Docker stack
  • How to push a local database dump into a docker container?
  • FROM centos:centos6
    
    # Upgrading system
    #RUN yum -y upgrade
    RUN yum -y install wget
    
    #Installing POSTGRESQL
    RUN rm /etc/yum.repos.d/CentOS-Base.repo
    
    COPY CentOS-Base.repo /etc/yum.repos.d/
    COPY startup.sh /root/
    
    RUN cd ~
    RUN (curl -O http://yum.postgresql.org/9.3/redhat/rhel-6-x86_64/pgdg-centos93-9.3-1.noarch.rpm && \
    rpm -ivh pgdg* && \
    yum list postgres* && \
    yum install -y  postgresql93-server && \
    service postgresql-9.3 initdb)
    echo "sh /root/startup.sh" >> ~/.bashrc
    EXPOSE 5432
    

    Few things which are very much required are – docker should be on Centos OS and PostgreSQL 9.3.

    I am running the below startup script (startup.sh file) for post installation activities –

    service postgresql-9.3 start
    su - postgres -c "psql -U postgres -c \"alter user postgres with password 'xxxxxxx';\""
    

    Now when i run the docker, it does installs and start the docker but throws the below error while trying to run the alter user postgres with password ‘xxxxxxx’ command.

    Any suggestions how i can run the “psql” commands like the alter password above or may be something like loading schema from .sql file post installation automatically in docker container.

    Thanks,

    AJ

  • What is POSTGIS_VERSION 2.1.7+dfsg-3~94.git954a8d0.pgdg80+1?
  • How can a script distinguish Docker Toolbox and Docker for Windows?
  • docker swarm container connect to host port
  • Nvidia Theano docker image not available
  • Rails - Enabling Nginx with https inside a Docker container using Phusion Passenger
  • Connection reset: set up Oracle SSL in docker
  • Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.