Fix for rmi throws error "no such id".

Closes #9056. Also closes #9170. Thanks @coolljt0725 for the start!
Includes integration-cli test, I am not necessarily in love with, but it is necessary evil. :smiling_imp: 
technically `WalkHistory` does this, so I didn't think it was necessary https://github.com/docker/docker/blob/039aa2741fa95ecb21e35a20d60d72018d8296c9/image/image.go#L197