Docker Assignment– 4
Multi-Container Applications with Docker Compose
Basic Questions
- Install Docker Compose on your system and verify the version.
- Write a simple docker-compose.yml with one service running nginx.
- Run the nginx service using docker-compose up.
- Stop the running service using docker-compose down.
- List all containers started by Docker Compose.
- Add a custom network in your docker-compose.yml.
- Add a named volume in your docker-compose.yml.
- Attach the nginx service to both a custom network and a volume.
- Write a Compose file with two services: nginx and alpine.
- Verify that the nginx and alpine containers can ping each other.
- Use docker-compose ps to list service details.
- Use docker-compose logs to view logs of all services.
- Run docker-compose exec to open a shell in the nginx container.
- Add environment variables to a service in the Compose file.
- Override an environment variable at runtime using .env file.
- Build a service from a Dockerfile using Compose.
- Tag the built image with a custom name.
- Inspect the created network from Docker Compose.
- Inspect the created volume from Docker Compose.
- Document the YAML structure: version, services, networks, volumes.
Intermediate Questions
- Write a docker-compose.yml with two services: nginx (web) and mongo (db).
- Use volumes to persist MongoDB data.
- Use environment variables to set MongoDB root username and password.
- Connect the nginx and mongo services on the same network.
- Write a Compose file with three services: nginx, node-app, and mongo.
- Configure node-app to connect to mongo via environment variables.
- Mount a custom HTML file into the nginx container using volumes.
- Mount source code into the node-app container for live development.
- Scale the node-app service to 3 instances using docker-compose up –scale.
- Verify load balancing among scaled node-app containers.
- Use docker-compose logs node-app to check logs from all scaled containers.
- Restart a specific service with docker-compose restart.
- Pause a service with docker-compose pause and unpause it.
- Use depends_on to ensure mongo starts before node-app.
- Use healthchecks in the Compose file for mongo service.
- Configure resource limits (CPU, memory) for the node-app service.
- Attach multiple services to the same named volume.
- Run docker-compose config to validate your Compose file.
- Override the Compose file with docker-compose.override.yml.
- Save logs of a service into a file using redirection.
Advanced Questions
- Write a complete docker-compose.yml for nginx + node-app + mongo.
- Configure persistent storage for MongoDB using a named volume.
- Configure the Node.js app to read DB credentials from environment variables.
- Configure Nginx as a reverse proxy for the Node.js app.
- Add healthchecks for all three services.
- Scale Node.js service to 3 replicas and connect through Nginx.
- Configure resource limits for each service (CPU/memory).
- Deploy the Compose stack and verify end-to-end functionality of web + db.
- Write a second Compose file for production (with resource limits) and override the default one.
- Document and demonstrate the full workflow: Write Compose file → Create network & volume → Start services → Scale app → Access via browser → Stop and clean up.