Gunmen attacked a military site north of the Iraqi capital on Wednesday, killing 12 soldiers, police and a doctor said.