Lock state before we modify.

When we start a container we lock state, we should do the same in stop.

Detected via -race.
Merge pull request #2795 from pnasrat/docker-testmultipleattachrestart-race

Lock state before we modify.