Can I create custom image in compose file or should write it in a separate Dockerfile?

I’m new to docker, so I’m asking for help.

Can I create custom image in compose file or should write it in a separate Dockerfile?

Thanks in advance.

Well, the Dockerfile is for the image, the compose file is for the services and you can refer to a Dockerfile from compose file in order to build the images before running the services.