Skip to main content

Mini-Projects for Docker, Docker Swarm

 Mini-Projects for Docker


Challenge 1

Welcome to the Docker challenge, your task is to follow the below steps and complete them successfully.

Step 1: Pull latest nginx image

Step 2: Create a new bridge 'bridge_sample'

Step 3: Run a couple of images (Cont1 and Cont2) and connect these to the new bridge created. Now try to ping from cont1 to cont2 to verify connectivity.

Step 4: Stop containers

Step 5: Remove network, containers, and images using docker commands

Note: Execute "history -w" in the terminal before submitting the scenario.

Before moving to Answers try to solve yourself...


Let's get started...

Step 1: Pull latest nginx image

docker pull nginx:latest

Step 2: Create a new bridge 'bridge_sample'

docker network create bridge_sample

Step 3: Run containers and connect them to the new bridge

docker run -d --name Cont1 --network bridge_sample nginx:latest
docker run -d --name Cont2 --network bridge_sample nginx:latest

Step 4: This step is optional if Cont1 already has the 'iputils-ping' installed, else install this in Cont1

docker exec -it Cont1 /bin/bash
#inside the Cont1
    apt update
    apt install -y iputils-ping
    exit
#exit from Cont1

Step 5: Ping from Cont1 to Cont2 to verify connectivity

docker exec -it Cont1 ping Cont2

This step verifies that Cont1 can successfully ping Cont2 over the 'bridge_sample' network.

Step 6: Stop containers

docker stop Cont1 Cont2

Step 6: Remove network, containers, and images

docker network rm bridge_sample
docker rm Cont1 Cont2
docker rmi nginx:latest

Note: Removing containers and images will permanently delete them, so please ensure you have backed up any important data before proceeding.

And that's it! The challenge is complete.

Once you are comfortable with this challenge now lets move to next challenge.






Challenge 2

Welcome to the Docker challenge, your task is to follow the below steps and complete them successfully.

Step 1: Initialize Docker Swarm
Step 2: Create a Docker Service with the following details:
                image: tomcat:8.5.78-jrell-temurin
                name: http
                Replicas: 2
                port: 88
                update-delay: 10s

Step 3: Update the above Service with a newer image tomcat:8.5-alpine

Step 4: Scale the above Service to 4 replicas

Step 5: Create a Docker overlay network with name app-network

Step 6: Step Update http service and add it to app-network network

Step 7: Step Create a secret with name redis password and content Pass@123

Step 8: Create another Docker Service with the following details:
                image: redis:alpine
                name: redis
                secret: redis_password
                mode: global

Step 9: Update the Leader node and add a label color=red

Step 10: Create a docker service with tomcat:8.5-alpine image with name tomcat-red-only. Add a constraint that the service will be deployed on node with label color=red

Here are the commands to achieve the steps outlined



Let's get started...

Step 1: Initialize Docker Swarm

docker swarm init

Step 2: Create a Docker Service with the given details:

docker service create --name http --replicas 2 --publish 88:80 --update-delay 10s tomcat:8.5.78-jrell-temurin

Step 3: Update the above Service with a newer image tomcat:8.5-alpine

docker service update --image tomcat:8.5-alpine http

Step 4: Scale the above Service to 4 replicas

docker service update --replicas 4 http

Step 5: Create a Docker overlay network with name app-network

docker network create --driver overlay app-network

Step 6: Update http service and add it to app-network network

docker service update --network-add app-network http

Step 7: Create a secret with name redis_password and content Pass@123

echo "Pass@123" | docker secret create redis_password -

Step 8: Create another Docker Service with the given details:

docker service create --name redis --secret redis_password --mode global redis:alpine

Step 9: Update the Leader node and add a label color=red

docker node update --label-add color=red self

Step 10: Create a Docker service with tomcat:8.5-alpine image with name tomcat-red-only. Add a constraint that the service will be deployed on a node with label color=red

docker service create --name tomcat-red-only --constraint 'node.labels.color==red' tomcat:8.5-alpine

Note: These commands assume that you are running them on the Docker Swarm manager node. If you are running them on a worker node, you may need to add the appropriate --host or --tls options to connect to the Docker Swarm manager. Also, make sure that you have Docker Swarm mode enabled on your Docker installation before executing these commands.


---THANK YOU---

Popular posts from this blog

Kubernetes2

  Challenge 2 ConfigMaps: Step-1: To create a ConfigMap named 'fresco-config' with the key-value pair SERVER_URL= https://www.fresco.me , use the following command: kubectl create configmap fresco-config --from-literal=SERVER_URL=https://www.fresco.me To verify if the ConfigMap is created, use the following command: kubectl get configmap fresco-config Step-2: To create an nginx pod with the environmental variable SERVER_URL_ENV using the ConfigMap created earlier, use the following YAML template: apiVersion: v1 kind: Pod metadata: name: fresco-nginx-pod spec: containers: - name: fresco-nginx-container image: nginx env: - name: SERVER_URL_ENV valueFrom: configMapKeyRef: name: fresco-config key: SERVER_URL Deploy the above file you can name it deployment.yaml and use the command: kubectl apply -f deployment.yaml To test your configuration by executing the following command: ...

Kubernetes1

  Challenge 1 Welcome to the Kubernetes challenge, your task is to follow the below steps and complete them successfully. Environment Setup Check whether docker & minikube are properly installed and configured. Start Minikube and execute this command to sync host docker with minikube docker minikube -p minikube docker-env and eval $(minikube docker-env) Step-1 Create a pod object using kubectl run command with google's sample image: gcr.io/google-samples/kubernetes-bootcamp:v1 and expose it on port 8080, name the pod as firstapp. Check if the pod creation is successful by running the command: kubectl get pod firstapp Step-2 Expose the application to the local VM by creating a Service object of type NodePort. Check if the service is created by running the command: kubectl get svc firstapp Step-3 Create another deployment using a 'YAML' file, create a deployment.yaml file that contains information of the number of replicas and the images to be ...

Docker + Kubernetes + Ansible

  Docker + Kubernetes + Ansible ----------------------------------------------------------------------------------------------------------------------------- Web Application Deployment using Kubernetes and Ansible A Flask application named "application.py" is given in the path Run the given setup.sh file given in the path to install the required dependencies be the challenge. 1. Start Minikube and sync host Docker with Minikube Docker. Note: If you get any errors while starting Minikube, please do try again by running the command to start Minikube. 2. Create a Dockerfile in the path and dockerize the given 'Flask' application as 'webapp-img' using 'python:alpine3.7' as its base image. 3. Create a 'deployment.yml' file in the path to create a Kubernetes deployment object named "web-deployment" with 3 replicas which uses the 'webapp-img' and runs a container named "webapp-container". Add Label "app=webapp" an...