Fix panic in validate context for build

Fixes #7611

Signed-off-by: Michael Crosby <michael@docker.com>