Docker-compose.yml or Dockerfile?

i’m pretty new to Docker and playing around. We have about 20 virtual machines with different Linux flavors (Suse, Ubuntu) in different versions, mostly with databases (Postgres, MySQL) and webservers (Apache, nginx, Tomcat). Because of load problems we want to migrate to containers in a HA solution.
I’m currently reading a lot and creating my first containers.
I stumbled across Dockerfile and docker-compose.yml. Both seem to be able to create images from which i derive containers. But which way is to prefer ?
What are the differences between them ?


Compose file with Docker Compose = multi container single host orchestrator. Supports image builds using Dockerfiles.
Compose file with Swarm = multi container multi host orchestrator. Does not support image builds.
Dockerfile = Blueprint with instructions on how to build an image.

None of them builds images. Both files are just configurations. Dockerfile is to define the Docker image that you want to build. The compose file is to define the containers/services and you can refer to a Dockerfile if you want to run a container from an image that does not exist yet.