0
0
Spring Bootframework~20 mins

docker-compose for services in Spring Boot - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Docker Compose Mastery - Spring Boot
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What happens when you run this docker-compose.yml?

Given this docker-compose.yml file for two Spring Boot services, what will be the result after running docker-compose up?

version: '3.8'
services:
  app1:
    image: springboot-app1:latest
    ports:
      - "8080:8080"
  app2:
    image: springboot-app2:latest
    ports:
      - "8081:8080"
    depends_on:
      - app1
Spring Boot
version: '3.8'
services:
  app1:
    image: springboot-app1:latest
    ports:
      - "8080:8080"
  app2:
    image: springboot-app2:latest
    ports:
      - "8081:8080"
    depends_on:
      - app1
AOnly app2 starts; app1 is ignored because it has no depends_on.
BBoth app1 and app2 start; app2 waits for app1 to start before launching.
COnly app1 starts; app2 fails because depends_on is not a valid key.
DBoth app1 and app2 start simultaneously without waiting for each other.
Attempts:
2 left
💡 Hint

Check what depends_on does in docker-compose.

📝 Syntax
intermediate
2:00remaining
Which docker-compose.yml snippet is valid for linking two Spring Boot services?

Choose the valid docker-compose.yml snippet that correctly links serviceA and serviceB so serviceB can access serviceA by hostname.

A
version: '3'
services:
  serviceA:
    image: springboot-a
  serviceB:
    image: springboot-b
    depends_on:
      - serviceA
B
version: '3'
services:
  serviceA:
    image: springboot-a
  serviceB:
    image: springboot-b
    depends_on:
      - serviceA
    links:
      - serviceA
C
version: '3'
services:
  serviceA:
    image: springboot-a
  serviceB:
    image: springboot-b
    links:
      - serviceA
D
version: '3'
services:
  serviceA:
    image: springboot-a
  serviceB:
    image: springboot-b
    network_mode: service:serviceA
Attempts:
2 left
💡 Hint

Remember that links is deprecated but still valid in version 3 for hostname resolution.

state_output
advanced
2:00remaining
What is the exposed port of app2 in this docker-compose setup?

Given this docker-compose.yml, what port on the host machine will map to app2's internal port 8080?

version: '3.8'
services:
  app1:
    image: springboot-app1
    ports:
      - "8080:8080"
  app2:
    image: springboot-app2
    ports:
      - "9090:8080"
Spring Boot
version: '3.8'
services:
  app1:
    image: springboot-app1
    ports:
      - "8080:8080"
  app2:
    image: springboot-app2
    ports:
      - "9090:8080"
A8080 and 9090
B8080
C8081
D9090
Attempts:
2 left
💡 Hint

Look at the port mapping format: hostPort:containerPort.

🔧 Debug
advanced
2:00remaining
Why does app2 fail to connect to app1 in this docker-compose setup?

Consider this docker-compose.yml snippet:

version: '3.8'
services:
  app1:
    image: springboot-app1
    ports:
      - "8080:8080"
  app2:
    image: springboot-app2
    ports:
      - "8081:8080"

App2 tries to connect to app1 using localhost:8080 but fails. Why?

Spring Boot
version: '3.8'
services:
  app1:
    image: springboot-app1
    ports:
      - "8080:8080"
  app2:
    image: springboot-app2
    ports:
      - "8081:8080"
ABecause app2's localhost refers to itself, not app1; it should use the service name 'app1' instead.
BBecause the ports are mapped incorrectly; app1 should expose 8081 instead of 8080.
CBecause app2 needs a depends_on key to start after app1.
DBecause docker-compose does not support multiple services communicating.
Attempts:
2 left
💡 Hint

Remember how Docker networking works between containers.

🧠 Conceptual
expert
2:00remaining
What is the effect of adding 'restart: always' to a service in docker-compose?

In a docker-compose.yml file for Spring Boot services, what does adding restart: always do?

AIt makes the service restart automatically if it stops or the Docker daemon restarts.
BIt forces the service to restart every 5 minutes regardless of status.
CIt disables manual stopping of the service via docker-compose commands.
DIt restarts the service only if the container exits with an error code.
Attempts:
2 left
💡 Hint

Check the official Docker Compose restart policies.