Dockerfile vs docker-compose.yml

docker, docker-compose, dockerfile, linux

Solution

`Dockerfile`:

- is a recipe for a Docker Image

- only supports portable options (others options have to be specified at container run time)

`docker-compose.yaml`:

- is a recipe for a group of running services

- supports overriding portable options that were defined in the `Dockerfile`

- supports non-portable options

- supports creating and configuring networks and volumes

- can also configure the build of an Image by using `build:`

It is common to use both together.

A `Dockerfile` is almost always used to create a custom image. Some images might be used to run services (long running processes), but some images might be used to run short-lived interactive processes (like running unit tests).

`docker-compose.yaml` is useful when you want to run one or more services.

Problem

What's the relation between `Dockerfile` and `docker-compose.yml` files? Looks like I can build any Linux setup using `Dockerfile` using `FROM`, `RUN` (`apt-get` etc. and `CMD` commands. But it seems, this is not much reusable (I can reuse the whole image, but the services are hardcdoded and not reusable by other projects). Shall I use both of the files on new projects? Let's say I want to have regular LAMP stack: - Linux OS (`debian:wheezy`) - Apache web server (`httpd:2.2`) - MySQL (`mariadb`) - PHP (`php:5.6`) running together as on one, regular machine. And in a dir on my host system: - volume for app source files - vhost config file - apache logs - persistent data in db I prefer using official, base repos and images, not the pre-configured all-in-ones. How the config files are supposed to look like in this case? I'm using `docker-compose` v.1.8.1 and `docker` v. 1.12.3 on Ubuntu.

Original source