CEDAR RAPIDS, Iowa — Iowa’s second-largest city has managed to keep flooding at bay largely because of barriers that were widely used to protect soldiers in Bosnia, Iraq and Afghanistan.

Crews in Cedar Rapids hastily erected Hesco barriers along nearly 10 miles of the Cedar River through neighborhoods and downtown. As of Tuesday morning, the sand-filled containers had protected thousands of properties, some up to 4 feet beneath the surging waterway.

The barriers are a key reason Cedar Rapids officials are hopeful they can largely avoid flooding, unlike in 2008 when higher river levels inundated 10 square miles of the city, causing billions of dollars in damage.

“In 2008, we felt defenseless,” Mayor Ron Corbett said. “In 2016, we took action and mobilized.”

The barriers were invented by British entrepreneur James Heselden, a former coal miner who used them to stop erosion on his property. After his invention received media attention, the United Kingdom’s military realized the barriers could be used to replace sandbags that protected soldiers from blasts in Bosnia, said Aaron Ackley, Hesco’s director of emergency response.

The U.S. military came to the same conclusion and began using the barriers extensively in Iraq and Afghanistan, eventually totaling more than 30,000 miles of the containers, said Ackley, who first saw the barriers when he served with the U.S. Army in Bosnia.

“There’s an unbelievable amount deployed for military use,” Ackley said. “Every air base, every forward-operating base, every fire base is surrounded by Hesco.”

As they were used more extensively by the military, emergency planners around the U.S. and the Army Corps of Engineers realized their ability to quickly protect against flooding and they have grown in popularity.

New York City has installed a network of what it calls “geotextile” bags along Rockaway Beach, weighing a total of 50 million pounds, to help protect the shoreline after Hurricane Sandy, said Meghan Lalor, a spokeswoman for the city’s parks department. Containers also have been used to prevent flooding recently in Monroe, Louisiana, along the Los Angeles River in Los Angeles and spots in New Mexico where wildfires destroyed plants and led to increased flooding risks.

The barriers are comprised of steel mesh panels, lined with a thick polypropylene material that can be quickly filled with sand or dirt, usually using a front-loader. The barriers keep water from seeping through to the other side, but allow moisture to drain out the bottom.

Cedar Rapids Assistant City Manager Sandi Fowler said the city bought 1½ miles of Hesco barriers in 2010 as part of its flood protection plan, but this marks the first time they have been deployed. Through Hesco, the city acquired the rest of its 9.8 miles from the University of Iowa, which had them in storage. The new Hescos cost $1.4 million, but with labor costs added, the entire temporary flood system totaled about $5 million.

Such selling and sharing of the barriers is common as new disasters arise. Fowler said the city has given its Hesco barriers to other communities facing flooding twice since 2010, and they have then been replenished by the company. They have been stored in different municipal buildings around the city.

“Ours haven’t been sitting on the shelf for six years,” Fowler said.

Fowler said the city hired contractors to install the barriers, which are then wrapped in plastic to repel water. Sandbags are used to hold the plastic onto the barriers.

During floods elsewhere, the city learned that Hesco barriers would tip over because the river undermines the ground beneath them, so Cedar Rapids placed them on concrete city streets and trails.

“We’re feeling very good, very, very confident, that this temporary system that we built in less than two days will protect our city,” City Manager Jeff Pomeranz said.