# Table of Contents 1. [Tooling List](#Tooling-list) 2. [Dockerfiles](#Dockerfiles) 3. [Steps to Recreate](#Steps-to-recreate) 4. [Journal](#Journal) # Tooling list ### Host Operating System Details ``` Operating System: macOS Ventura 3.1 (22C65) Chipset: Apple M1 pro ``` ### Software Used ``` Docker: Docker version 25.0.2, build 29cf629 ``` # Dockerfiles ### Dockerfiles runs 'grep': ``` FROM alpine:latest RUN apk add --no-cache curl grep COPY search.sh /search.sh CMD ["/search.sh"] ``` ### Dockerfile runs 'cat': ``` FROM python:3.8-alpine RUN pip install Flask # Set a working directory WORKDIR /app # Copy the Flask app to the container COPY app.py /app/app.py COPY cattext.txt /app/cattext.txt # The command to run the Flask app CMD ["flask", "run", "--host=0.0.0.0"] ``` # Steps to recreate: ### Step 1: Install docker on your host machine. Go to this url(https://docs.docker.com/engine/install/) and download the correspond file to the computer system. ![1.DOWNLOAD_DOCKER](https://hackmd.io/_uploads/Skjj0c0ip.png) ### Step 2: Create docker bridge network Run this command in the terminal ``` docker network create gc-network ``` ![2.CREATE_NEWTWORK](https://hackmd.io/_uploads/H18n0cCia.png) ### Step 3: Create Flask app ``` from flask import Flask, send_file app = Flask(__name__) @app.route('/file') def file(): return send_file('cattext.txt', as_attachment=True) if __name__ == "__main__": app.run(host='0.0.0.0') ``` ### Step 4: Create search text file Here we use `cattext.txt` as the resource file for search ``` cattext.txt Here is the keyword for search. This line does not contain word for search. But this line has keyword. ``` ### Step 5: Create search script for grep ```search.sh # Search for 'keyword' in the txt file get from network curl http://cat-container:5000/file | grep "keyword" ``` ### Step 6: Build Dockerfile for grep ```Dockerfile.grep FROM alpine:latest RUN apk add --no-cache curl grep COPY search.sh /search.sh CMD ["/search.sh"] ``` ### Step 7: Build Dockerfile for cat ```Dockerfile.cat FROM python:3.8-alpine RUN pip install Flask # Set a working directory WORKDIR /app # Copy the Flask app to the container COPY app.py /app/app.py COPY cattext.txt /app/cattext.txt RUN chmod 666 /app/cattext.txt # The command to run the Flask app CMD ["flask", "run", "--host=0.0.0.0"] ``` ### Step 8: Build images of cat-image and grep-image ``` docker build -t cat-image -f Dockerfile.cat . docker build -t grep-image -f Dockerfile.grep . ``` ![10.CONTAINER_CREATED](https://hackmd.io/_uploads/Bkdx1sCj6.png) ### Step 9: Run Containers ``` docker run --network=gc-network -itd --name=cat-container cat-image docker run --network=gc-network -itd --name=grep-container grep-image ``` ![11.RUN_CAT_CONTAINER](https://hackmd.io/_uploads/HJD0AcRja.png) ![12.RUN_GREP_CONTAINER](https://hackmd.io/_uploads/r1xJyiRip.png) ### Step 10: See the output of the search operation result on Docker * Output of cat-container ``` 2024-02-17 15:22:12 * Debug mode: off 2024-02-17 15:22:12 WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead. 2024-02-17 15:22:12 * Running on all addresses (0.0.0.0) 2024-02-17 15:22:12 * Running on http://127.0.0.1:5000 2024-02-17 15:22:12 * Running on http://172.18.0.2:5000 2024-02-17 15:22:12 Press CTRL+C to quit 2024-02-17 15:23:35 172.18.0.3 - - [17/Feb/2024 20:23:35] "GET /file HTTP/1.1" 200 - ``` * Output of grep-container The grep-container successfully find the lines in cattext.txt that contains "keyword". ``` 2024-02-17 15:23:35 % Total % Received % Xferd Average Speed Time Time Time Current 2024-02-17 15:23:35 Dload Upload Total Spent Left Speed 100 102 100 102 0 0 40637 0 --:--:-- --:--:-- --:--:-- 51000 2024-02-17 15:23:35 Here is the keyword for search. 2024-02-17 15:23:35 But this line has keyword. ``` # Journal I spent over twice the amount of time on this assignment compared to the previous one. I invested considerable effort in designing and mastering the use of Docker networking between two containers to accomplish the search task. Eventually, I devised a method of transferring files from the 'cat-container' to the 'grep-container' via URL, enabling the output of search results. Witnessing it successfully print out the result brought me a great sense of accomplishment.