Add docker upstart pre-stop and post-start events to prevent race conditions

An attempt to fix issue #6647