If you use your own file without using the container, some code won’t work. You may refer to the index.php of the project and copy code to create the container, e.g.
$containerBuilder = new ContainerBuilder();
$containerBuilder->addDefinitions("src/definitions.php");
$container = $containerBuilder->build();
That’s why you should avoid the old way of using standalone files, nowadays it is better to treat your application as an integrated app, not a group of standaone files. Avoid accessing standalone files by xxx.php in the URL. You may want to read Using Route_Action server event.