A Compose service is a named containerized application declared under `services:` in `compose.yaml`. It gives Docker Compose a repeatable definition for building or obtaining a container image and running the application. Instead of retyping options for `docker run`, put settings such as ports and environment variables in the service definition. section 6.2.2
Listing 6.3 Docker Compose for our Python app
services:
web:
build:
context: .
dockerfile: Dockerfile
ports:
- "8080:8080"
environment:
- PORT=8080
This `web` service builds the Python application from the current directory’s Dockerfile, maps host port 8080 to container port 8080, and sets `PORT=8080`. section 6.2.2
From the project directory, run `docker compose build` to build the image, `docker compose up` to run the service, and `docker compose down` to stop it. These commands use the declared configuration rather than requiring the port and environment options on each run. section 6.2.2
A Compose file can declare more than one service. Compose provides a network between their containers, and a service name works as a hostname on that network. For example, a Python `web` container can request `http://my-nginx-service:80` from an NGINX service. The NGINX service needs no host port mapping for that container-to-container request. section 6.4.1
Listing 6.9 NGINX service in Docker Compose
services:
my-nginx-service:
image: nginx
web:
build:
context: .
dockerfile: Dockerfile
ports:
- "8080:8080"
environment:
- PORT=8080
volumes:
- mywebdata:/app/data
volumes:
mywebdata:
Compare the two services: `web` is built locally and publishes a port, while `my-nginx-service` uses the public NGINX image without publishing one. section 6.4.1
For a load-balancing setup, separate service names can run the same Python image. NGINX can then address those names as upstream destinations and distribute requests among them. This example duplicates service declarations rather than introducing an automatic scaling command. section 7.4.1
Do not confuse a Compose service with a Kubernetes `Service` resource. The Compose definition describes a containerized application; a Kubernetes Service has its own manifest and can direct traffic to containers selected by labels. section 6.2.2 section 8.3.4

