Most real applications are not a single container but a collection of cooperating services such as a web server, an application server, and a database. Docker Compose is a tool for describing such multi-container applications declaratively in a YAML file called docker-compose.yml, which lists each service along with its image, ports, environment, networks, and volumes. Compose keeps the configuration in source control so the whole application stack can be brought up, torn down, or recreated in a single step.
To launch the defined application you run docker-compose up, which builds or pulls the necessary images, creates the required networks and volumes, and starts all the services together. Adding the -d flag runs everything in detached mode so the terminal remains free. To observe what is happening, docker-compose logs service_name prints the logs for a named service, or omits the name to see logs from every service at once. Compose effectively turns a multi-container application into one command-line operation.
When you need to run containers across many machines rather than one, Docker Swarm provides clustering and orchestration. You initialize a cluster with docker swarm init, which turns the current node into a manager and prints a join token for worker nodes. Inside a Swarm, a Docker service describes the desired state of a group of containers: which image to run, how many replicas, what networks to attach, and what resources to allocate. You deploy one with docker service create --name name --replicas N image and inspect the cluster with docker service ls. Swarm also provides Docker secrets, which are encrypted objects for storing sensitive data such as passwords. Secrets are mounted into services through in-memory tmpfs filesystems so the data never touches the container image or disk. Overlay networks complement Swarm by enabling multi-host container communication using VXLAN encapsulation, allowing containers on different physical nodes to talk to one another securely and transparently.