How do I run PHPUnit tests? Having just kind of gotten my head around Simpletest functional testing in Drupal 8.x, I've now started trying to use PHPUnit testing since Simpletest has been deprecated in Drupal 9.1.x.
I started by looking at the instructions on Running PHPUnit tests. However, when I get to the step on running the tests I get this.

Fatal error: Uncaught Error: Class &quot;Drupal\Tests\node\Functional\NodeTestBase&quot; not found in /opt/drupal/web/core/modules/node/tests/src/Functional/PagePreviewTest.php:22

This looks a bit like an autoload issue to me. I ran the following command to verify it was effectively so.
php -r &quot;require_once('autoload.php'); var_dump(class_exists('\Drupal\Tests\node\Functional\PagePreviewTest'));&quot;

The command outputs bool(false).
My knowledge really ends here. The documentation seems to be moot on this, and it looks like I'm not the only one with this problem. (See How to run PHPUnit tests?).
How do I run PHPUnit tests?
This is the Docker file content that can be used to reproduce what I described in the question.
FROM drupal:9.1.0

RUN composer require -n \
  phpunit/phpunit:9.5.0 \
  phpspec/prophecy-phpunit:2.0.1 \
  symfony/phpunit-bridge:5.2.1

RUN cd web/core; phpunit -c phpunit.xml.dist modules/node/tests/src/Functional/NodeTestBase.php

Building this causes the error I described above.
I believe the problem is that you are using the sample phpunit.xml.dist instead of copying it to phpunit.xml and then making a few teaks for your installation.
Part of the phpunit.xml file is setting up the autoloader to find test classes and modules (they are not in the normal autoloader). And you tend to get some really weird errors if you don't set up the DSN for the database (to run Kernel and Functional tests).
I would do the following (adjust paths as needed ; I'm looking at a core-dev project right now and not a live site).

In your install, do composer require --dev drupal/core-dev:~9.1.0. You may want to tweak the version number, depending on you you have core defined.
Make sure you are running the binary from vendor/bin in your install.  I suggest looking into direnv.
Copy phpunit.xml.dist to phpunit.xml and edit

SIMPLETEST_BASE_URL
SIMPLETEST_DB
BROWSERTEST_OUTPUT_DIRECTORY
to reflect your installation.



Then cd to core, and run
../vendor/bin/phpunit -c phpunit.xml --testsuite unit

This should start to loop through the Unit tests. Abort that if they look like they are working, and then do
../vendor/bin/phpunit -c phpunit.xml --testsuite kernel

Then, if that looks OK you can start to run your own tests.
All of that said, it is much easier to run individual tests through PhpStorm. You just need to got through the preferences to point to the right PHP interpreter, and set a few things for phpunit.
In your case, it may be better to just start the drupal:9.1.0 container, and then shell into it for initial testing before updating the Dockerfile.