What Is a docker-compose.yml File?

What is a docker-compose.yml file?

It is a file used by the docker-compose utility which orchestrates the creation of multiple containers. For microservices, SOA and various stacks of applications (e.g., the LAMP stack), container orchestration is useful. Here are some quotes which help elucidate what docker-compose does:

"Compose is a tool for defining and running multi-container Docker applications." (Taken from Docker's website.)

"In order to do something useful with containers, they have to be arranged as part of a project, usually referred to as an ‘application’. This is what a docker-compose.yml file does, specifying what images are required, what ports they need to expose, whether the have access to the host filesystem, what commands should be run, and so on." (Taken from Divio.com.)

"A docker-compose.yml file is a YAML file that defines how Docker containers should behave in production." (Taken from Docker's website.)

The docker-compose is "a command-line utility to define and run multicontainer applications with Docker." taken from page 198 from The Docker Cookbook by Goasguen.

The docker-compose utility looks for and uses a docker-compose.yml file in the directory that you run the "docker-compose" command. This utility supports the keyword "depends" in the docker-compose.yml file. This "depends" conditions a container starting on another container starting. If you run "docker-compose up foobar" (where foobar is a service in the docker-compose.yml file), the command will start the services that "foobar" depends on, as designated in the docker-compose.yml file. Without specifying a service name, the docker-compose up command will start all of the services.

Here is an example of a docker-compose.yml file:

version: '3'
      image: mysql
      container_name: mysql_db
      restart: always
         - MYSQL_ROOT_PASSWORD="secret"
     image: apache
     build: ./webapp
        - db
     container_name: apache_web
     restart: always
       - "8080:80"

The above was taken from from Tecadmin.net.

If you want to try a docker-compose.yml file out, see this posting.

To learn more about the file itself and its reserved words, see this.

Leave a comment

Your email address will not be published. Required fields are marked *