[dockerfile mode] Clean up state machine

Issue #2964