This is a docker forum and your problem is related to PHP. You probably need to read some more docs…
BUT make sure rdkafka is well installed !
You are running container ans once in a console you are thus (from what I understand) installing the extension by hand.
Are you then running your php code in the exact same container ?
What you should understand when you installing things by hand in a container is it’s not permanent. When you’ll suit the container you’ll loose your manual changes.
To make installation persistent, it should be installed using a dockerfile (my previous link).
But I’m not sure what that is supposed to mean. So pleas, share the base image, if you have a shareable Dockerfile, please share that too.
I’m also confused about this:
As far as I know, php index.php just runs the index.php in command line without any webserver. That would only be a command line application and command line applications and PHP behind webservers use different configs and can load different extensions.
I don’t see how php index.php could run any web-based php app (unless using some parameters to run the built-in webserver), but I assume you you are using an image where the extension is loaded in one PHP but not in the other if you have multiple PHP in the same image. Official PHP images for example have a PHP built from source, so extension paths and configs could be different.