Dockerfiles are to build an image for example from a bare bone Ubuntu, you can add mysql called mySQL on one image and mywordpress on a second image called mywordpress.
Compose YAML files are to take these images and run them cohesively.
For example, if you have in your docker-compose.yml file a service called db:
services:
db:
image: mySQL --- image that you built.
and a service called wordpress such as:
wordpress:
image: mywordpress
then inside the mywordpress container you can use db to connect to your mySQL container. This magic is possible because your docker host create a network bridge (network overlay).