docker-compose
is an easy to use container orchestration manager that sits on top of Docker nicely. It ships with Docker.
docker-compose
and docker compose
The command used to be docker-compose
but recently changed to docker compose
. I like to alias docker-compose="docker compose"
in my shell so that I don’t have to care.
Using Host Network
For some use cases it may be useful to bind the container’s network stack to the host so that calls to ports on localhost go to the right place. To do this add the following to your docker-compose service:
Extensions and Fragments
Docker-compose yaml defines mechanisms for reusing parts of the configuration so that it is possible to minimise repetition.
The worked examples illustrate the point of this functionality:
- We use the prefix
x-
to denote configurations that are template and docker-compose ignores them. - We use
&varname
to set up a reference to the yaml data structure that sits underneath it - We use
<<: *varname
to inject those variables into a later service.