Docker Assignment– 6
Docker Orchestration & Advanced Features
Basic Questions
- Enable Docker Swarm mode on your system using docker swarm init.
- List all nodes in your Swarm cluster using docker node ls.
- Create a simple service running nginx in Swarm mode.
- List all services running in the Swarm.
- Scale the nginx service to 3 replicas.
- Verify that 3 containers are running across the cluster.
- Inspect the details of the nginx service.
- Update the service image from nginx:alpine to nginx:latest.
- Remove the nginx service.
- Create a stack file (docker-compose.yml) with one service and deploy it using docker stack deploy.
- List all stacks in Swarm.
- Inspect the stack you created and list its services.
- Remove the stack using docker stack rm.
- Run a service with a memory limit of 256M.
- Run a service with a CPU limit of 0.5.
- Add a health check to an nginx service using CMD-SHELL curl -f http://localhost/.
- Inspect the service to verify the health check configuration.
- Add a restart policy that restarts containers on failure.
- Remove all services in the Swarm cluster.
- Leave the Swarm mode using docker swarm leave –force.
Intermediate Questions
- Create a service that runs a redis container in Swarm mode.
- Scale the redis service to 5 replicas.
- Deploy a stack with 2 services: nginx (web) and redis (db).
- Add a rolling update configuration to the nginx service with 1 replica updated at a time.
- Pause a rolling update in the middle of deployment.
- Resume the paused rolling update.
- Rollback the service to its previous version.
- Create a secret named db_password in Swarm.
- Deploy a MySQL service that uses the db_password secret.
- Inspect the MySQL container to confirm the secret is mounted.
- Create a service with environment variables defined inside the stack file.
- Deploy a stack with a persistent volume for MySQL.
- Set CPU and memory limits for both services in a stack file.
- Add health checks to both services in the stack.
- Use a restart policy on-failure with maximum retries set to 3.
- Use placement constraints to schedule a service only on manager nodes.
- Create an overlay network and connect multiple services to it.
- Deploy a service with two published ports (80 and 443).
- Inspect logs of a Swarm service using docker service logs.
- Update stack configuration and redeploy it using docker stack deploy.
Advanced Questions
- Create a stack with three services: Nginx (frontend), Node.js (backend), and MongoDB (database).
- Configure secrets for MongoDB username and password in the stack.
- Add CPU and memory limits for each service in the stack.
- Add health checks for all three services.
- Configure rolling updates for the backend service with parallelism set to 2.
- Configure restart policies so failed services automatically recover.
- Scale the backend service to 5 replicas and verify load distribution.
- Perform a zero-downtime update of the frontend service.
- Rollback the frontend service to its previous version after update.
- 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.