You can add wildcard domains on fly.io, see e.g. Limitations with respect to wildcard certs or domains per app? - #7 by Zane_Milakovic
Then, handle forward on within your application (or probably on some reverse proxy which you are using inside your image, like nginx).
as an example,
server {
listen 80;
server_name ~^(?<subdomain>.+)\.example\.com$;
location / {
rewrite ^ https://example.com/$subdomain permanent;
}
}