Good catch! I mixed it in my head with what I saw in this thread, which used an fpm based image.
It is best practice to have everything required available in the image. It is high likely that an image with mysqli/php does already exist on dockerhub. Though, depending on the reputation (downloads/stars) of such image(s) it might be still more usefull to build your own custom image:
The custom image approach will be self contained as everything required to run your application will comme with the image vs. the approch where you install package during the start of the container (which by the way will be executed whenever the container is started), which introduces external runtime dependencies to a repository that might be not always available or packages get removed (which with the mysqli package is highly unlickely I guess).
Generaly an image should contain the core service, all its dependencies and a usefull base configuration to run a container based from it. Idealy the image has a clever entrypoint script to override settings in the configurations OR at least allows to mount existing configs into the container.
I am sure you already know this: a container is supposed to be ephemeral and persistant data is supposed to be stored in volumes to be persisted outside the container.