YAML is a human-readable format for structured, machine-readable documents. In a microservices application, a YAML file can describe how Docker Compose builds and launches containers, or how Kubernetes deploys a service. section 4.3.2 section 8.9.1
A Docker Compose YAML file can assemble a service configuration from small, readable fields:
- Declare the Compose version and the services collection. section 4.3.2
- Define a service with an image name, build context, Dockerfile, and container name. section 4.3.2
- Configure port bindings, environment variables, and restart behavior. section 4.3.2
- Keep the application-level Compose file in the root directory while placing each microservice in its own subdirectory. section 4.3.2
A service definition
The file can define a video-streaming service with image video-streaming, build context ./video-streaming, Dockerfile Dockerfile, port mapping 4000:80, environment variable PORT=80, and restart behavior set to no. section 4.3.2
Listing 4.1 Docker Compose file for our microservice
version: '3' #1
services: #2
video-streaming: #3
image: video-streaming #4
build: #5
context: ./video-streaming #6
dockerfile: Dockerfile #7
container_name: video-streaming #8
ports: #9
- "4000:80" #10
environment: #11
- PORT=80 #12
restart: "no" #13
Inspect the complete Compose listing to connect YAML fields with image building, container naming, port binding, environment configuration, and restart behavior. section 4.3.2















