Docker Assignment– 4

Multi-Container Applications with Docker Compose

Basic Questions

  1. Install Docker Compose on your system and verify the version.
  2. Write a simple docker-compose.yml with one service running nginx.
  3. Run the nginx service using docker-compose up.
  4. Stop the running service using docker-compose down.
  5. List all containers started by Docker Compose.
  6. Add a custom network in your docker-compose.yml.
  7. Add a named volume in your docker-compose.yml.
  8. Attach the nginx service to both a custom network and a volume.
  9. Write a Compose file with two services: nginx and alpine.
  10. Verify that the nginx and alpine containers can ping each other.
  11. Use docker-compose ps to list service details.
  12. Use docker-compose logs to view logs of all services.
  13. Run docker-compose exec to open a shell in the nginx container.
  14. Add environment variables to a service in the Compose file.
  15. Override an environment variable at runtime using .env file.
  16. Build a service from a Dockerfile using Compose.
  17. Tag the built image with a custom name.
  18. Inspect the created network from Docker Compose.
  19. Inspect the created volume from Docker Compose.
  20. Document the YAML structure: version, services, networks, volumes.

Intermediate Questions

  1. Write a docker-compose.yml with two services: nginx (web) and mongo (db).
  2. Use volumes to persist MongoDB data.
  3. Use environment variables to set MongoDB root username and password.
  4. Connect the nginx and mongo services on the same network.
  5. Write a Compose file with three services: nginx, node-app, and mongo.
  6. Configure node-app to connect to mongo via environment variables.
  7. Mount a custom HTML file into the nginx container using volumes.
  8. Mount source code into the node-app container for live development.
  9. Scale the node-app service to 3 instances using docker-compose up –scale.
  10. Verify load balancing among scaled node-app containers.
  11. Use docker-compose logs node-app to check logs from all scaled containers.
  12. Restart a specific service with docker-compose restart.
  13. Pause a service with docker-compose pause and unpause it.
  14. Use depends_on to ensure mongo starts before node-app.
  15. Use healthchecks in the Compose file for mongo service.
  16. Configure resource limits (CPU, memory) for the node-app service.
  17. Attach multiple services to the same named volume.
  18. Run docker-compose config to validate your Compose file.
  19. Override the Compose file with docker-compose.override.yml.
  20. Save logs of a service into a file using redirection.

Advanced Questions

  1. Write a complete docker-compose.yml for nginx + node-app + mongo.
  2. Configure persistent storage for MongoDB using a named volume.
  3. Configure the Node.js app to read DB credentials from environment variables.
  4. Configure Nginx as a reverse proxy for the Node.js app.
  5. Add healthchecks for all three services.
  6. Scale Node.js service to 3 replicas and connect through Nginx.
  7. Configure resource limits for each service (CPU/memory).
  8. Deploy the Compose stack and verify end-to-end functionality of web + db.
  9. Write a second Compose file for production (with resource limits) and override the default one.
  10. Document and demonstrate the full workflow: Write Compose file → Create network & volume → Start services → Scale app → Access via browser → Stop and clean up.