Building my own postgresql image

Hi,
The image is built successfully, but I want to create the database on it at the time it is built. Everytime I do so it gives me the error that the postgresql is down.
When I create/build the image without that script which is suppose to create the databases it works fine.
How can I get the databases created at the time I am building the image with Dockerfile ?
Part of my Dockerfile is as follows

VOLUME ["/var/lib/pgsql"]
USER postgres
CMD ["/bin/bash", “/usr/local/bin/postgresql.sh”]
EXPOSE 5432

RUN /var/lib/pgsql/CreateDatabase.sh

you need to start the database on your own in a RUN statement and within the same RUN statement you also need to run your database setup script (CreateDatabase.sh). after that shut down the database again.
Should write this in a little script.

Could look similar to this:

#!/bin/bash
/usr/local/bin/postgresql.sh&
sleep 2m
/var/lib/pgsql/CreateDatabase.sh
shutdown_postgres