You have probably noticed that your shared code was different from what you wanted to share. Please, follow the below guide next time and use code blocks for code snippets.
You are not using the official image. This topic is about the official Docker image for PHP. I share the link again since it was shared years ago: https://hub.docker.com/_/php
The image description shows you how you can add extensions.
With the official image you don’t even need to use apt to install extensions maybe only dependencies of the extensions. If you have a specific problem or please share that with an error message in case you have one and share what you have tried before to solve the problem.