The compose file is a YAML file that is used for the Docker application to define services, networks, volumes, secrets, and configs. By default docker-compose.yaml
(preferred) or docker-compose.yml
is used. You can define your own custom compose file and use it as compose file also.
Similar to passing command-line options to docker run, a service definition contains a configuration that will be applied to each container launched for that service. As with docker network create
and docker volume create
, network and volume definitions are comparable.
The same as with docker run, the options supplied in the Dockerfile (such as CMD, EXPOSE, VOLUME, and ENV) are taken into account by default; you do not need to supply them again in docker-compose.yml.
For example, you have a database and web which are a part of your application. All of your services rely on an image with which we create a container. And there may be many options; and how these options are configured will be in docker-compose.yaml
or compose.yaml
or in your custom compose file.
Sample docker-compose.yml file
services:
frontend:
image: cloudyfox/webapp
build: ./webapp
backend:
image: cludyfox/database
build:
context: backend
dockerfile: ../backend.Dockerfile
custom:
build: ~/custom
Here,
cloudyfox/webapp
docker image is built using webapp
sub-directory within compose file as a docker build context. If no Dockerfile
is in this directory, an error will be thrown.cloudyfox/database
docker image is built using backend
sub-directory. backend.Dockerfile
is used to define build steps.custom
directory as a docker context.On push, two docker images cloudyfox/webapp
and cloudyfox/database
are pushed to the registry. While custom
service image is skipped as there is no image
attribute.