If the range of $f$ is finite and it has more than one point, then $f$ is discontinuous (since the range is not connected) but $f$ maps compact sets onto compact sets.