Docker Assignment– 6

Docker Orchestration & Advanced Features

Basic Questions

  1. Enable Docker Swarm mode on your system using docker swarm init.
  2. List all nodes in your Swarm cluster using docker node ls.
  3. Create a simple service running nginx in Swarm mode.
  4. List all services running in the Swarm.
  5. Scale the nginx service to 3 replicas.
  6. Verify that 3 containers are running across the cluster.
  7. Inspect the details of the nginx service.
  8. Update the service image from nginx:alpine to nginx:latest.
  9. Remove the nginx service.
  10. Create a stack file (docker-compose.yml) with one service and deploy it using docker stack deploy.
  11. List all stacks in Swarm.
  12. Inspect the stack you created and list its services.
  13. Remove the stack using docker stack rm.
  14. Run a service with a memory limit of 256M.
  15. Run a service with a CPU limit of 0.5.
  16. Add a health check to an nginx service using CMD-SHELL curl -f http://localhost/.
  17. Inspect the service to verify the health check configuration.
  18. Add a restart policy that restarts containers on failure.
  19. Remove all services in the Swarm cluster.
  20. Leave the Swarm mode using docker swarm leave –force.

Intermediate Questions

  1. Create a service that runs a redis container in Swarm mode.
  2. Scale the redis service to 5 replicas.
  3. Deploy a stack with 2 services: nginx (web) and redis (db).
  4. Add a rolling update configuration to the nginx service with 1 replica updated at a time.
  5. Pause a rolling update in the middle of deployment.
  6. Resume the paused rolling update.
  7. Rollback the service to its previous version.
  8. Create a secret named db_password in Swarm.
  9. Deploy a MySQL service that uses the db_password secret.
  10. Inspect the MySQL container to confirm the secret is mounted.
  11. Create a service with environment variables defined inside the stack file.
  12. Deploy a stack with a persistent volume for MySQL.
  13. Set CPU and memory limits for both services in a stack file.
  14. Add health checks to both services in the stack.
  15. Use a restart policy on-failure with maximum retries set to 3.
  16. Use placement constraints to schedule a service only on manager nodes.
  17. Create an overlay network and connect multiple services to it.
  18. Deploy a service with two published ports (80 and 443).
  19. Inspect logs of a Swarm service using docker service logs.
  20. Update stack configuration and redeploy it using docker stack deploy.

Advanced Questions

  1. Create a stack with three services: Nginx (frontend), Node.js (backend), and MongoDB (database).
  2. Configure secrets for MongoDB username and password in the stack.
  3. Add CPU and memory limits for each service in the stack.
  4. Add health checks for all three services.
  5. Configure rolling updates for the backend service with parallelism set to 2.
  6. Configure restart policies so failed services automatically recover.
  7. Scale the backend service to 5 replicas and verify load distribution.
  8. Perform a zero-downtime update of the frontend service.
  9. Rollback the frontend service to its previous version after update.
  10. Deliver a complete hands-on workflow: Initialize Swarm → Create secrets → Deploy stack (frontend + backend + db) → Apply resource limits and health checks → Perform rolling update → Scale services → Validate everything.