To train a dog with an invisible fence, use temporary white flags to mark the boundary. A trainer then teaches the pet to retreat based on warning sounds and static cues. Only remove flags after training is complete.