Does your dockerimage file have an ENTRYPOINT
i.e.
copy run2.sh /usr/local/bin/run2.sh
run chmod +x /usr/local/bin/run2.sh
ENTRYPOINT ["/usr/local/bin/run2.sh"]
Your run2.sh file should look something like this (so it can respond to Signals from the OS i.e. shutdown)
#!/bin/bash
#This is a run file - which should be used to add things you want your
#container to do when you start it up
#
#If you do not have this then ...
# docker-compose up ---- simply exists as there is nothing for the container to do.
trap cleanup 1 2 3 6 9 15
cleanup()
{
echo "Caught Signal ... cleaning up."
service postgresql stop
sleep 1s
echo "Done ... quitting."
exit 1
}
service postgresql start
# wait forever
echo "Starting up"
while true
do
tail -f /dev/null
done
Note:
This removes the necessity to start services, plus you get to specify the shutdown steps required.
If you want you can have multiple rules, I was just lazy and lobbed them all together.
Hope this helps....