Fix #8262: check tag's validity before building.

When user passes an invalid tag to `docker build`, check the tag first and terminate-early so user can specify the tag again.

Docker-DCO-1.1-Signed-off-by: Daniel, Dao Quang Minh <dqminh89@gmail.com> (github: dqminh)