Test fail randomly in CI but work fine locally

Hey guys,
I work for a company that uses circle ci for a couple of jobs we have running every time a Pull request is created for our repo. One of these jobs are tests for our react app.

For quite some time tests have been flaky for us in Circle CI while locally they work as expected. After some tries to blindly fix them based on errors in the end I tried to expand the resource_class of our circle ci config.yml file to large (and also increased jest timeout). This seem to have fixed the problem until around 2 months later it started happening again, but much less frequently (two weeks in between failures while before tests would fail every day multiple tests and multiple times). An engineer on our team suggested to try and run them using docker (since we have an image in which they run in circle job) but they work fine.

So to ask a concrete question to get a discussion started:

  1. Is it possible using docker to mimic the resources that circle ci gives to a specific job?
  2. If so how would one achieve this?
  3. Is there a better way to create an environment as close as possible to the circle ci one (regarding resources)?
  4. How are hardware resources shared in between jobs (for multiple jobs running at the same time)?