TWENTYNINE PALMS, Calif.—Fear that utility companies remain vulnerable to hackers, terrorists and natural disasters has the Pentagon pushing construction of independent power grids at military bases across the U.S., including one nearing completion here at the Marine Corps combat center.

The base at Twentynine Palms, home to about 22,000 people and spread across 1,100 square miles of the Mojave Desert, still buys power from Southern California Edison. But soon it will be able to operate even if there is a blackout, using a system of small power plants, solar panels, batteries and diesel generators. It already is saving $10 million a year in energy costs.

Dozens of U.S. bases are marching in the same direction as they try to keep up with the growing power demands of a modern military. “A lot of bases want what we’ve got,” said Gary Morrissett, the energy manager at Twentynine Palms.

The U.S. military needs an uninterrupted flow of electricity to support operations at home and around the globe, officials said. Drones in Afghanistan, for example, have been piloted from Creech Air Force Base in Nevada.

Diesel-run generators that provide backup power can’t do the job alone, given the electricity demands of the high-tech era.