Ensure docker cp stream is closed properly

Fixes #4039
Fixes #3986



Docker-DCO-1.1-Signed-off-by: Michael Crosby <michael@crosbymichael.com> (github: crosbymichael)