One of the main causes of front-loading washer odors is detergent buildup. Mineral deposits and dirty water also contribute to the odor. Although most of the water and detergent are rinsed out through the machine, some of it remains, which can lead to a sour smell.
Clean your washer by running a laundry-free complete wash cycle and add 2 cups of white vinegar or lemon juice to the detergent dispenser. Run another cycle with just hot water to rinse out the loosened grime. Scrub the rubber seal around the door with a rag and all-purpose cleaner, along with the detergent dispenser.
Leave the door of the washer opened when not in use to allow air to circulate. Remove laundry from the washer as soon as it's done so a musty smell doesn't form. Run a "clean" cycle with vinegar or lemon juice about once a month to keep the machine clean.