Unit 3 - Practice Quiz
1 What is a primary characteristic of a monolithic application architecture?
2 Why do modern applications often use a microservices architecture?
3 How does microservices architecture improve scalability?
4 What does fault isolation mean in the context of microservices?
5 What is the primary role of an API Gateway in a microservices architecture?
6 What file format is primarily used by Docker Compose for its configuration files?
7
What is the default filename Docker Compose looks for when you run the docker-compose up command?
8
What does the version field at the top of a docker-compose.yml file specify?
9
In a docker-compose.yml file, what does the services section define?
10
What is the purpose of defining volumes in Docker Compose?
11
What is the function of the networks field in a docker-compose.yml file?
12 How do you pass configuration settings, like database passwords, to a container in Docker Compose?
environment or env_file keywords in the YAML file.
13
What is the difference between the build and image directives in Docker Compose?
build tells Compose to build an image from a Dockerfile, while image specifies a pre-built image to pull from a registry.
build downloads a pre-made image, while image deletes it.
build starts the container, while image stops it.
14 Which Docker Compose keyword is used to express dependency between services, ensuring one starts before another?
15 In Docker Compose, what is the best practice for handling highly sensitive data like API keys or TLS certificates?
16 In a standard three-tier multi-container application, what does the backend container usually do?
17 When deploying a WordPress application using Docker Compose, which database is traditionally paired with it as a separate service?
18 Why is MongoDB frequently paired with Node.js in multi-container deployments (the MEAN/MERN stack)?
19 When using Docker Compose to deploy a Java Spring Boot backend, what kind of service is PostgreSQL?
20 How do microservices improve agility for development teams?
21 An e-commerce application is experiencing high traffic exclusively on its payment processing module during a sale. How does a microservices architecture handle this more efficiently than a monolithic architecture?
22 In a microservices architecture involving a UI frontend and multiple backend services (e.g., users, orders, inventory), what is the primary role of an API Gateway?
23 A developer introduces a memory leak in the 'Reporting' microservice. Under a microservices architecture, how does the 'isolation' advantage prevent a system-wide outage?
24
When defining a docker-compose.yml file, what does the version field primarily dictate?
25
A PostgreSQL database container is destroyed and recreated using Docker Compose, resulting in complete data loss. Which configuration should be added to the docker-compose.yml to prevent this in the future?
deploy: restart_policy to prevent the container from ever being destroyed.
depends_on flag to ensure the database boots before the backend.
volumes key.
networks key to isolate the database from the backend.
26
Which of the following represents the correct hierarchical structure for defining a web service mapped to port 80 in docker-compose.yml?
27
If an environment variable DB_PASS is defined in an .env file, and simultaneously defined under the environment section of a service in docker-compose.yml with a different value, what will be the value inside the container?
.env file, as it takes global precedence.
docker-compose.yml file, as it overrides the .env file.
28
You have a frontend service and a backend service in docker-compose.yml. You want the backend to communicate with the database, but the frontend should NOT be able to reach the database. How can this be achieved?
expose directive on the database so it is only visible to the host machine.
frontend_net, backend_net), connect the backend to both, the frontend to frontend_net, and the database to backend_net.
network_mode: isolated for the database service.
29
In a docker-compose.yml, what happens if a service defines BOTH the build and image fields?
image field.
image tag, assigning a random hash as the name.
build field and exclusively pulls the image from Docker Hub.
30
A Node.js backend crashes upon startup because the MongoDB container it depends on is still initializing, even though depends_on: - mongo is used. What is the correct way to ensure the backend waits until MongoDB is fully ready to accept connections?
depends_on with condition: service_started.
depends_on with condition: service_healthy and configure a healthcheck in the MongoDB service.
sleep 30 command inside the docker-compose.yml for the backend.
restart: always on the MongoDB container to speed up its boot time.
31 When passing highly sensitive data like an API token to a service in Docker Compose, why is using Docker Secrets generally preferred over standard environment variables?
docker inspect.
32 When deploying a WordPress + MySQL stack using Docker Compose, how does the WordPress container know how to locate the MySQL database?
WORDPRESS_DB_HOST to the service name of the MySQL container.
localhost IP into the WordPress configuration.
3306 on both containers so they share the network stack.
33
A developer sets up a Node.js backend and a MongoDB database. The database service is named mongo_db. What should the Mongoose connection string look like in the Node.js application?
mongodb://localhost:27017/myapp
mongodb://docker-host:27017/myapp
mongodb://127.0.0.1:27017/myapp
mongodb://mongo_db:27017/myapp
34
In a Docker Compose deployment of a Spring Boot app and a PostgreSQL database, the Spring Boot application configuration (application.properties) has spring.datasource.url=jdbc:postgresql://postgres_server:5432/mydb. Which of the following MUST be true in docker-compose.yml for the connection to work?
postgres_server or have an alias of postgres_server on the shared network.
latest image tag.
network_mode: host.
5432 to the host machine using ports: - "5432:5432".
35 You are deploying a 3-tier application (React frontend, Express backend, PostgreSQL database) using Docker Compose. The React frontend runs in a user's browser. How should the frontend make API calls to the backend?
localhost or the public domain/IP where the backend's port is exposed.
http://backend:8080).
36
A developer writes the following snippet in docker-compose.yml:
yaml
ports:
- 8080:80
What does this mapping signify?
37 A legacy monolithic application uses a single relational database for all transactions. As the user base grows, database locks cause widespread performance issues. How does a microservices architecture address this specific 'Need for microservices'?
38
If Service A depends on Service B in a docker-compose.yml file, what happens when you execute docker-compose stop Service B?
39
A developer wants to keep database credentials out of the docker-compose.yml file tracked in Git. They place the credentials in an .env file. What is a crucial best practice regarding this .env file?
.env file to .gitignore so it is never committed to the version control repository.
.env file to .config so Docker Compose hides it automatically.
.env file to a public Docker Hub repository.
.env file to Git but encrypt it using Base64 encoding.
40
Consider the volumes configuration in a Docker Compose service:
yaml
volumes:
- mydata:/var/lib/mysql
Where must mydata be defined for this configuration to be completely valid at the file level?
volumes: block at the end of the docker-compose.yml file.
.env file as VOLUME_NAME=mydata.
VOLUME instruction.
41 A team is migrating a legacy monolithic application to a microservices architecture. They notice that transactions previously handled by a single ACID-compliant database commit now span multiple distinct services and databases. Which of the following architectural patterns is most appropriate to manage data consistency across these services?
42
In a Docker Compose deployment containing an API Gateway and multiple scaled instances of a backend service (e.g., docker-compose up --scale backend=3), how does the API Gateway natively resolve the internal routing to distribute traffic among the backend instances?
docker-compose.yml file at runtime to map host ports to individual container IPs.
backend to a single IP that acts as a physical load balancer.
docker-compose mode.
backend, and the API Gateway must rely on DNS Round Robin or client-side load balancing.
43
When designing a complex docker-compose.yml file, you need multiple services to share identical logging configurations, environment variables, and restart policies without duplicating code. Which YAML feature is natively utilized in Compose to achieve this DRY (Don't Repeat Yourself) principle?
defaults: block at the top of the Compose file and inheriting it via the inherit: key.
template: key under each service to reference a standardized JSON configuration file.
&) on extension fields (prefixed with x-) and merging them into services using aliases (<<: *).
docker-compose.common.yml file and importing it using the include directive inside the services block.
44
Service A has a depends_on configuration pointing to Service B with the condition service_healthy. Service B defines a healthcheck in the Compose file. If Service B starts successfully but its healthcheck repeatedly fails (returns unhealthy), what will Docker Compose do when starting the environment?
45
Consider the following environment variable hierarchy in Docker Compose. You have an environment variable DB_PORT set to 5432 in the .env file, DB_PORT=5433 exported in your host OS shell, DB_PORT=5434 defined in an env_file referenced in the Compose file, and DB_PORT: 5435 defined directly under the environment: key of the service. What value will the container actually use for DB_PORT?
46
In a docker-compose.yml file, a service defines both the build: ./webapp and image: custom-webapp:v2 keys simultaneously. What is the precise behavior when docker-compose up -d is executed, assuming the image custom-webapp:v2 does not exist locally?
./webapp, tags the resulting image as custom-webapp:v2, and runs the container from it.
./webapp with a random name, but aliases it to custom-webapp:v2 in the internal DNS.
build instruction and attempts to pull custom-webapp:v2 from Docker Hub, failing if it's not found.
build and image are mutually exclusive fields.
47
A docker-compose.yml file provisions a PostgreSQL database using a named volume db_data mounted at /var/lib/postgresql/data. Upon the very first startup, the named volume is completely empty, but the PostgreSQL base image already contains default database configuration files at /var/lib/postgresql/data. What happens to these files?
nocopy flag.
48
You are deploying a multi-tier application using Docker Compose with three services: frontend, backend, and database. You want frontend to only communicate with backend, and backend to communicate with both frontend and database. The database should be completely unreachable from the frontend. Which network configuration enforces this isolation?
app_net. Assign frontend, backend, and database to it, and use Docker's network_policy key to restrict traffic.
front_net and back_net. Attach frontend to front_net, database to back_net, and backend to both front_net and back_net.
expose key on the database service to only accept connections from the backend container's IP.
database in an internal: true network and frontend in an external: true network, while backend acts as a reverse proxy using links.
49
In a non-Swarm local Docker Compose deployment, a service is configured to use a secret defined via a file (e.g., file: ./db_password.txt). How is this secret materialized inside the running container, and what are the security implications compared to environment variables?
docker inspect but still visible to child processes.
/run/secrets/), which avoids exposing sensitive data in environment variables or docker inspect outputs.
/var/lib/docker/secrets, requiring the application to decrypt it using a private key.
50
A docker-compose.yml file contains the following environment variable declaration for a service: APP_TIMEOUT: ${TIMEOUT:?Error: TIMEOUT is not set}. If the user runs docker-compose up without defining the TIMEOUT variable in their shell or .env file, what is the exact outcome?
APP_TIMEOUT variable, removing it from the container's environment.
TIMEOUT with the string "?Error: TIMEOUT is not set" and starts the container.
51
A microservices deployment features a Java Spring Boot application and a PostgreSQL database in Docker Compose. The spring-boot service depends_on the postgres service with condition: service_healthy. However, the Spring Boot application intermittently crashes on startup, throwing a Connection refused exception. Which of the following is the most likely architectural root cause?
depends_on asynchronously, meaning Spring Boot can occasionally bypass the healthcheck lock if the host CPU is under heavy load.
service_healthy condition guarantees the PostgreSQL container is running, but it does not guarantee that PostgreSQL is ready to accept TCP connections on port 5432.
postgres hostname before Docker's embedded DNS is fully initialized.
docker-entrypoint-initdb.d take longer, causing a race condition.
52
You are setting up a Node.js application backed by a MongoDB Replica Set using Docker Compose. A Replica Set requires an initialization command (rs.initiate()) to be run exactly once after the MongoDB nodes start. What is the most robust and Docker-native way to handle this initialization in a docker-compose.yml file?
rs.initiate() command inside the Node.js application's startup script to guarantee the database is configured before API requests are served.
deploy.replicas key in Docker Compose to automatically inform MongoDB that it should bootstrap a replica set cluster.
mongo-setup service that depends_on the MongoDB nodes, runs a script with rs.initiate(), and immediately exits with restart: "no".
mongod && mongo --eval "rs.initiate()" so initialization happens simultaneously with startup.
53
A user deploys WordPress and MySQL using Docker Compose. They map the WordPress container's port to 8080:80 and the MySQL container's port to 3306:3306. In the WordPress configuration (WORDPRESS_DB_HOST), they specify localhost:3306. When they navigate to http://localhost:8080, WordPress fails to connect to the database. Why does this happen, and how should it be fixed?
WORDPRESS_DB_HOST must point to the Docker host gateway IP address.
WORDPRESS_DB_HOST should be set to 127.0.0.1:3306.
WORDPRESS_DB_HOST should be changed to the service name of the MySQL container (e.g., db:3306).
docker-compose.yml must include a build step to install mysqli before setting the host to localhost.
54
In the modern Compose Specification (integrated into Docker Compose V2), the top-level version: element (e.g., version: '3.8') behaves differently than in classic docker-compose V1. Which of the following statements accurately describes the handling of the version key in modern Compose?
version key is strictly enforced, and modern Compose will crash if it detects a version lower than '3.0'.
version key is deprecated and purely informational; modern Compose dynamically merges v2.x and v3.x features (like depends_on: condition and deploy: resources) regardless of the declared version.
version key determines whether Compose uses the Docker Swarm orchestrator or the local Docker Engine API.
version key dictates the YAML schema syntax, requiring users to specify version: 'compose-spec' to use the latest features.
55 An organization adopted microservices to increase release agility. However, they now find that every time they update the 'Order' service, they must also deploy specific versions of the 'Inventory' and 'Billing' services simultaneously to prevent system crashes. What architectural anti-pattern has the organization likely created?
56
In a complex docker-compose.yml, Service A depends on Service B, Service B depends on Service C, and Service C depends on Service A. All dependencies are standard (no healthcheck conditions). What is the outcome when docker-compose up is executed?
depends_on graph because a cycle is present.
57
You have a docker-compose.yml containing a primary web application and an optional debug-tools service. You want debug-tools to be completely ignored by default when running docker-compose up, but you want the ability to explicitly start it when troubleshooting. Which Docker Compose feature is explicitly designed to handle this scenario?
scale: debug-tools=0 default parameter inside the Compose file.
debug-tools service under a profiles: array (e.g., profiles: ["debug"]).
debug-tools inside an override file and setting depends_on: [].
restart: never policy on the debug-tools service.
58
A team wishes to leverage Docker Compose to horizontally scale a backend Node.js microservice (docker-compose up --scale backend=5). The backend uses an in-memory cache to store user session tokens. Which of the following issues will occur, and what is the required architectural change to support this scaling?
59 In a multi-container deployment, the frontend container (React/Nginx) needs to make API calls to the backend container (Express/Node.js). The frontend container is mapped to host port 3000, and the backend is mapped to host port 5000. In the React application code running in the user's browser, which base URL should be used to fetch data from the backend?
http://frontend:3000/api/ because React automatically reverse-proxies all requests to connected internal networks.
http://backend:80/ because internal Docker communication bypasses port mappings and requires the default HTTP port.
http://localhost:5000/ (or the host's public IP) because the React code executes client-side in the user's browser, outside the Docker network.
http://backend:5000/ because Docker's internal DNS automatically resolves the service name for the browser.
60 When introducing an API Gateway (like Traefik or Nginx) to a Docker Compose microservices architecture, you decide to implement SSL/TLS termination and JWT token validation directly at the Gateway. What is the primary architectural advantage of this approach?