Bird
0
0

Which of the following is the correct way to specify a service's port mapping in a docker-compose.yml file?

easy📝 Syntax Q12 of 15
Spring Boot - Docker and Deployment
Which of the following is the correct way to specify a service's port mapping in a docker-compose.yml file?
Aports: - "8080:8080"
Bports: 8080:8080
Cport: 8080->8080
Dexpose: 8080:8080
Step-by-Step Solution
Solution:
  1. Step 1: Recall docker-compose port syntax

    Ports are listed as a YAML array with dash and quotes, like ports: - "hostPort:containerPort".
  2. Step 2: Check options

    ports: - "8080:8080" matches the correct YAML syntax for port mapping.
  3. Final Answer:

    ports: - "8080:8080" -> Option A
  4. Quick Check:

    Port mapping uses dash and quotes in YAML [OK]
Quick Trick: Use dash and quotes for ports in docker-compose YAML [OK]
Common Mistakes:
  • Omitting dash for list items
  • Using wrong key 'port' instead of 'ports'
  • Confusing 'expose' with 'ports'

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes