A VM virtualizes hardware and runs a full kernel per guest. A container shares the host kernel and isolates a process. That one difference explains almost everything else.
There’s no if/else instruction in Dockerfile syntax. Conditional behavior comes from either shell conditionals inside RUN, or picking a different build stage entirely.