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 –

  • access mysql with kubernetes : access denied for user root
  • How do you put your source code into Kubernetes?
  • Docker container connect to host DocumentDB emulator
  • AWS Elastic Beanstalk Docker PHP application
  • Docker and HttpCallback
  • Difference between service and container in docker compose
  • 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

  • Connecting docker locally with vagrant provisioned docker
  • Where to find the tomcat folder in the docker image
  • Updating a Symfony app with Docker-compose without losing data
  • Deploying a .NET Core Web API using Docker on Elastic Beanstalk
  • Docker Java memory usage
  • Docker env variables not set while log via shell
  • Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.