How does PullPreview know how to setup my environment?

PullPreview uses docker and a docker-compose file to setup an environment with your application dependencies, as well as any external service dependencies (redis, mysql, postgresql, etc). To enable PullPreview on your repository, you should have a working Dockerfile, as well as docker-compose file that can launch a working environment without any human interaction.

I already have my docker-compose.yml file, but I need to do some changes for PullPreview

By default, PullPreview will first try to read a docker-compose.pullpreview.yml file, and only fallback to docker-compose.yml if it does not find one.

Do you support docker-compose v2?

For now only v1 is supported, but you can easily write a docker-compose file specific to PullPreview by naming it docker-compose.pullpreview.yml, and keep your current docker-compose file untouched.

Any restrictions in terms of the docker-compose file?

Yes, only the following attributes are supported:

Do I need to specify the external ports for my services?

It's up to you. If you only specify the internal port, then a port will be automatically assigned for you. You can choose any external port for your services.

Can I persist data across preview sessions?

Yes. If you specify a volume with an explicit host mount point (e.g. volumes: ["./exports/db:/var/lib/postgresql/data"]), a persistent volume will be created for the duration of the branch or pull request life, and that volume will be attached to any new session started.
This means that you can choose to keep your database data across deployments (for a specific branch / pull request) by specifying a volume for your database data directory.