The second stage of the rocket puts the capsule into earth orbit.
The command module stays in orbit around the moon.
After launch the booster stage of the rocket is released and the second stage fires.
After a few earth orbits, the engine is ignited again to shoot the capsule towards the moon. The engine is shut down once out of earth orbit and then the command module disconnects, turns around, and moves in to dock with the lunar lander, which is housed in the top of the rocket stage.
Once lunar orbit is established, two of the three astronauts move into the lunar lander and the lander is disconnected from the command module. A retro-rocket on the lunar lander is fired and slows the lander so that the moon’s gravity will pull it to the surface.
Near the moon, the command module turns so that when its engine is fired it will slow down the command module to go into a lunar orbit.
Once docked together, the command module pulls the lunar lander out.