Improve scripting to rebuild docker images

Change-Id: I2f2a30ade23518133e24c4addcaae86890b2c9ab
Reviewed-on: http://review.couchbase.org/40998
Reviewed-by: Chris Hillery <ceej@couchbase.com>
Tested-by: Chris Hillery <ceej@couchbase.com>