There was a time when the sight of a Boston police uniform would have sent Mark Wahlberg racing in the other direction — way back during his troubled teens, when the now-respected actor and producer was arrested about 20 times for dealing drugs, running with a gang, and visiting cruel violence on fellow citizens.

That was then.

This is now: In Patriots Day, Wahlberg appears in uniform as a Boston Police Department sergeant, playing the lead in director Peter Berg's epic Hollywood thriller about the 2013 Boston Marathon bombing.

The film opens Friday.

"I certainly prefer being on this side" of the law, Wahlberg, 45, said in a recent phone chat.

A painstakingly researched account of the April 15 attack and subsequent manhunt for Dzhokhar and Tamerlan Tsarnaev, Patriots Day is an homage to his hometown and its people, Wahlberg said.

The film gave the Hollywood A-lister and his costars, including John Goodman, Michelle Monaghan, Kevin Bacon, and J.K. Simmons, an opportunity to spend time with first responders who were on the scene during the attack and with officers who scoured the city to find the bombers afterward.

Wahlberg said the city gave cast and crew a king's welcome.

He remembers "being in the [police] commissioner's office or being in the mayor's  office or being invited to these benefits for local law enforcement," he said. "I have a deep appreciation of being welcomed by that entire community with open arms."

Wahlberg was in New York on the day of the marathon attack and was shocked to see Boston shut down for the manhunt when he arrived there a day later.

"I remember coming out of the airport and seeing the city basically deserted," he said. "I'm still processing it."

He said he would finally be able to "sit back and really reflect on it" now that the film has wrapped.

Patriots Day is the third movie in an ongoing collaboration between Wahlberg and Berg, after 2013's Lone Survivor (about a deadly Navy Seal operation in Afghanistan) and 2016's Deepwater Horizon (about the offshore-drilling-rig explosion and oil spill in the Gulf of Mexico).

Wahlberg said each focused on the heroic actions of everyday American men and women faced with impossible situations.

For Patriots Day, which he coproduced, the filmmakers had two overriding goals, he said.

"We wanted [the film] to be as accurate as possible and to get in all the details we could. It's hard. We had two hours to tell a story that unfolded over more than 100 hours," he said.

"And we wanted to honor the people. … We've been able to [screen it] for the victims and their families and the first responders."

All other questions were pushed to the side, including political second-guessing.

"Did the police do the right thing" after the Boston bombing?, Wahlberg said, repeating a question. "Did the FBI treat Boston police and Boston's citizens with respect" during the investigation and manhunt?

"We didn't want to focus on the political … discussions about all the things that went on," said the actor.

"This is just about the people. … Ultimately, it was about the good that people did, all the efforts they put forward, and the resiliency they showed."