Examine where the top of the dishwasher meets your countertop, if it is fitted. There should be obvious brackets and screws. Tighten any loose screws and wiggle brackets back into the correct position. Replace missing screws if necessary; unscrew one of the remaining screws to determine the size.
Adjust the leveling screws or knobs on the feet of the dishwasher, if it is freestanding. Rocking often results from an uneven floor. Push down on either side of the top to determine when the machine is secure.
Fold pieces of thick cardboard, and wedge them underneath the machine and in the gap between the dishwasher and the countertop. This should temporarily stop the machine from rocking until it can be fixed or secured permanently.