# Docker Compose

If we want to setup a complex application with multiple services . A better way to do it is to use docker-compose. With Docker-compose we can create a comfiguration file in YAML format called docker-compose.yml & put together the different services & options specific to runnning them in the file .

\>>simply run docker-compose up command to bring up the entire application stack.

\>>Its only applicable only when we are running all our container on single DOCKER HOST.

![](/files/-MERdYCqIkNACse_eCBb)

<https://github.com/dockersamples/example-voting-app>

This voting app provides two options to choose between a Cat & a Dog.

![](/files/-MERe_vxhetp8noFgaQo)

Now see how we can put this entire stack on Single Docker Sever without using Docker Swarm:

links is used to link used two container together .

links are now depriciated . This is beacuse of the Docker Swarm & some advanced netwroking concepts:

Here we can see that Postgre & Redis already build on Docker registry so instead of pulling pass build option .

\>>>Now Docker compose first build the images then use those images to run conatiners using options that we specified.

version 1 is the original version of docker -compose&#x20;

In version 1 docker-compose attaches all the container to a default bridge network & then use links to enable communication between the containers .

In version 2 , automatically created a dedicated bridge netwrok for the application & then attaches all containers to that new netwrok. All container then comuunicate each other using service names. So there is no need to use links in version 2 of docker compose.

\>>Version 2 introduces depends-on feature&#x20;

\>> Version 3 is similar to version2 execpt it comes up with support of Docker Swarm.

![](/files/-MERkBPI0BBOi07EEF29)

&#x20;Now we have created two networks front-end & back-end:

1\) front-end : a front-end network dedicated for traffic from users generated traffic.

2\) a back-end netwrok dedicated for traffic within the application. We then connect the user facing applications voting-app & result-app with a front-end netwrok & all the components to internal back-end network.

![](/files/-MERlvIDfrIZL9JAuM8p)

Practical Implementation : example-voting-app

<https://github.com/dockersamples/example-voting-app>

\>>First we need to remove our containers that we created manaully in oder to run the application using docker-compose.

&#x20;

![](/files/-MERpkKeXsEii6CJ7P9v)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://architectures.gitbook.io/project/docker/docker-compose.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
