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
version: '3.8' services: app1: image: springboot-app1:latest ports: - "8080:8080" app2: image: springboot-app2:latest ports: - "8081:8080" depends_on: - app1
Check what depends_on does in docker-compose.
The depends_on key makes app2 wait for app1 to start before launching. Both services will run, but app2 starts after app1.
Choose the valid docker-compose.yml snippet that correctly links serviceA and serviceB so serviceB can access serviceA by hostname.
Remember that links is deprecated but still valid in version 3 for hostname resolution.
Option C uses links correctly to allow serviceB to access serviceA by hostname. Option C mixes depends_on and links unnecessarily. Option C lacks links so hostname access is not guaranteed. Option C uses an invalid network_mode value.
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"
version: '3.8' services: app1: image: springboot-app1 ports: - "8080:8080" app2: image: springboot-app2 ports: - "9090:8080"
Look at the port mapping format: hostPort:containerPort.
The port mapping "9090:8080" means the container's port 8080 is exposed on host port 9090.
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?
version: '3.8' services: app1: image: springboot-app1 ports: - "8080:8080" app2: image: springboot-app2 ports: - "8081:8080"
Remember how Docker networking works between containers.
Each container has its own localhost. To connect between containers, use the service name as hostname, not localhost.
In a docker-compose.yml file for Spring Boot services, what does adding restart: always do?
Check the official Docker Compose restart policies.
restart: always ensures the container restarts automatically if it stops for any reason or if Docker restarts.