rewrote to support docker 1.3+