cover photo

BLOG · 1/4/2025

MARVEL Level 2 Tasks Report: PART 2

Jeethan Tauro
Jeethan Tauro
OP
MARVEL Level 2 Tasks Report: PART 2

TASK 4: Docker

What did I learn?

  • So i learnt that Docker is used to package, distribute, and run applications in isolated environments called containers. It ensures that an application runs the same way on different machines, avoiding issues like "it works on my machine but not on yours. "

  • It packs all the necessary dependencies in a box and helps it to parcel to different clients so they can unbox and use it.

  • So to help understand docker this is the example and analogy i thought of:

    • Imagine you are developing a Java-based banking application on your laptop. It requires Java, MySQL, and some libraries. Instead of manually installing everything on every machine where you want to run the application, you can create a Docker container that includes the application and all its dependencies.
    • Now, you can run this container anywhere on another developer’s computer, a test server, or in the cloud without worrying about missing dependencies or configuration issues.
  • I also learned the difference between VM's and Containers :

    1. VMs have a full operating system (OS) inside them, including a separate kernel, making them heavy and slow to start.
    2. Containers share the host OS kernel, so they are lightweight and start almost instantly.
    3. VMs need more system resources, while containers use less memory and CPU.
  • Commands I learnt for using docker

    • docker ps → List running containers.
    • docker ps -a → List all containers (including stopped ones).
    • docker run → Run a container from an image.
    • docker start → Start a stopped container.
    • docker stop → Stop a running container.
    • docker restart → Restart a container.
    • docker kill → Forcefully stop a running container.
    • docker rm → Remove a stopped container.
    • docker logs → View the logs of a container.
    • docker images → List all available images.
    • docker pull → Download an image from Docker Hub.
    • docker push → Push an image to Docker Hub.
    • docker build -t . → Build an image from a Dockerfile.
    • docker tag → Tag an image with a new name.
    • docker rmi → Remove an image.
    • docker history → Show the history of an image.
    • docker inspect → Get detailed information about an image.
  • I learnt about docker compose :

    • Docker Compose is a tool that allows you to define and manage multi-container Docker applications using a YAML configuration file (docker-compose.yml). Instead of running multiple docker run commands manually, you can define all services, networks, and volumes in one file and start them with a single command.
      • docker-compose up → Start services defined in docker-compose.yml.
      • docker-compose down → Stop and remove services.
      • docker-compose ps → List running services.
      • docker-compose logs → View logs of services.
      • docker-compose restart → Restart all services.
  • I learnt the difference between images and containers:

    • Images are nothing but a blueprint or templates for a container, the images are read only and can be configured only once, they are reusable, they are stored in docker hub, they contain all the dependencies and a base OS - The application code - All dependencies (libraries, runtimes, configurations) - A base operating system (like Ubuntu, Alpine, etc.) - Any customized settings
    • Docker containers are nothing but the running instances of a docker image, it is the actual execution of the application in an isolated environment - Based on Images → Containers are created from images. - Read-Write Layer → Containers can modify their filesystem while running. - Isolated but Share the Host Kernel → Unlike Virtual Machines, containers share the host OS kernel but have their own filesystem, processes, and network. - Temporary (Ephemeral) or Persistent → Containers can be deleted after use or configured to keep data.

  • I learnt what a Dockerfile is and the use cases :

    • A Dockerfile is a text file that contains a set of instructions for building a Docker image. It acts as a blueprint for creating lightweight, portable, and consistent environments.
    • So if we have an application, if we want to convert that application into an image we just have to include a docker file into it.
    • Once our image is created we can upload it to dicker hub and then developers can pull our images form there. To pull images we can use the docker pull command
    • We can push our image to docker hub using docker push command
  • Instead of manually setting up software dependencies, a Dockerfile automates this process.


TASK 5: Docker File Spyware

What did I learn?

  • So here I learnt what a spyware is and what it generally does
    • Spyware is a type of malicious software (malware) that is designed to secretly monitor, collect, and transmit data from an infected device without the user's knowledge or consent. It often operates in the background, recording sensitive information such as:
      • Keystrokes (keyloggers)
      • Browsing history
      • Login credentials (usernames, passwords)
      • Personal data (emails, financial details)
      • Microphone & camera activity
    • Types of spyware:
      1. Keyloggers – Record everything typed on a keyboard.
      2. Adware – Tracks browsing habits to display targeted ads.
      3. Trojan-based Spyware – Disguised as legitimate software but secretly collects data.
      4. Tracking Cookies – Small files that track web activity across sites.
      5. System Monitors – Capture screenshots, record chats, and monitor internet usage.
  • In this task I learnt a lot about SSH, here i learn how to SSH into EC2 instances and then run docker on those EC2 instances. I also learnt how to manually transfer files using SSH scp
  • I learnt how to run a SH script to automate the task of transferring newly added images from one server to another server
  • So the steps I followed for this task is as follows:
    1. Launched 2 EC2 instances, first_server and second_server using the AWS website
    2. SSH into to first_server and installed docker and created a dockerfile that runs the monitor script and automates the process
    // Use a lightweight Linux base image
FROM ubuntu:latest

 //Install necessary dependencies
RUN apt-get update && apt-get install -y \
    inotify-tools \
    openssh-client \
    && rm -rf /var/lib/apt/lists/*

//Set environment variables
ENV WATCH_DIR=/watched_folder
ENV REMOTE_USER=ubuntu
ENV REMOTE_HOST=34.224.174.148
ENV REMOTE_PATH=/home/ubuntu/images

//Create necessary directories
RUN mkdir -p $WATCH_DIR

//Copy the monitor script into the container
COPY monitor.sh /monitor.sh
RUN chmod +x /monitor.sh

//Copy the SSH private key (for SCP)
COPY jeethan-key.pem /root/.ssh/jeethan-key.pem
RUN chmod 400 /root/.ssh/jeethan-key.pem

//Start monitoring when the container runs
CMD ["/bin/bash", "/monitor.sh"]
  1. Created a folder using the dockerfile where images will be uploaded in the first server:
    mkdir -p ~/watched_folder
    
    1. Created a folder where images will be received in the second server:
    mkdir -p ~/images
  1. Created the monitor.sh Script** - This script monitors the watched_folder for new images and automatically transfers them to SECOND_EC2 using scp.
#!/bin/bash

	WATCH_DIR="/home/ubuntu/watched_folder"
	REMOTE_USER="ubuntu"
	REMOTE_HOST=""
	REMOTE_PATH="/home/ubuntu/images"
	KEY_PATH="/home/ubuntu/jeethan-key.pem"
	
	# Ensure the watched directory exists
	mkdir -p "$WATCH_DIR"
	
	echo "Monitoring $WATCH_DIR for new files..."
	
	# Start monitoring directory for new files
	inotifywait -m -e create "$WATCH_DIR" --format "%f" |
	while read FILE; do
	    echo "New file detected: $FILE"
	    scp -i "$KEY_PATH" "$WATCH_DIR/$FILE" "$REMOTE_USER@$REMOTE_HOST:$REMOTE_PATH"
	    if [ $? -eq 0 ]; then
	        echo "File successfully transferred: $FILE"
	    else
	        echo "Error transferring file: $FILE"
	    fi
	done
  • And done we just have to upload the images in the first_server and it will be trasferred - - ~ Click here for part 3

UVCE,
K. R Circle,
Bengaluru 01