Starting multiple docker containers and let them communicate

When developing microservice-like architectures it is reasonable to assume that docker is used for deploying the individual services. In order to test if the services worke together properly, especially on a small scale, on can start a docker container for each service. Since each of the services gets its own network stack created by docker, they can by default not communicate with each other. It would be nice to have the possiblity to simply start all services at once and give them the possibility to communicate with each other using the hostnames of the services.
1 answer

Use docker-compose to easily start multiple docker containers

In order to easily start up multiple docker instances with one command, one could use docker-compose. This command line tool lets user specify a docker compose file, which uses YAML to define which containers need to be started and how they will be connected.
The exemplary definition for one docker container to be started would look like this (note that the indentaion is lost, because whitespace is trimmed)

CONTAINER_NAME:
image: TAG_OF_THE_IMAGE
links:
- NAME_OF_CONTAINER_1:LOCAL_NAME_OF_CONTAINER_1
- ...
- NAME_OF_CONTAINER_N:LOCAL_NAME_OF_CONTAINER_N
ports:
- "EXPOSED_PORT:MAPPED_PORT"

Here NAME_OF_CONTAINER_1 refers to the name under which another container was started by docker and LOCAL_NAME_OF_CONTAINER_1 specifies the hostname under which it will be reachable from within the container.

docker-compose is able to determine in which order the containers need to be started, but it cannot handle cyclic relations.