diff --git a/README.md b/README.md index 36aa346..dba10e3 100644 --- a/README.md +++ b/README.md @@ -1 +1,260 @@ -# corise-zignite-devops-cc \ No newline at end of file +# Intro to DevOps - Week 2 Project Starter Code + +# Goal +## Containerize two Flask web services and use Docker Compose to orchestrate them +### For our week 2 project, we will be containerizing two Flask apps, one generates a Random Quote, and the other service consumes this and displays it on a neat front end. +### Then we shall be using Docker Swarm to orchestrate the services to achieve our end goal. This exercise will help us understand a real-world use case of Docker and Docker Swarm better. + +## Prerequisites +
Basic knowledge of programming and APIs is needed.
+
The tutorial on how to start a Docker Container is here - https://docs.docker.com/language/python/build-images/
+ +## Environment Setup - Things needed to run Project 2 + +Install Docker Desktop from here - https://docs.docker.com/desktop/. +Choose the distribution of your choice but we will be using Windows. +Docker compose, the CLI tools come along with Docker Desktop. + +Download the starter file from here - (https://github.com/sb2nov/corise-zignite-devops-cc) + +Test if Docker is installed by running the following command in the terminal +``` +docker run hello-world +``` +If everything is installed right you get a response 'Hello from Docker! We are all good to go, let's start off our Week 2 project then! + +# Steps +Download or Clone the repo https://github.com/sb2nov/corise-zignite-devops-cc/tree/starter_code + +Create a Docker File within the cloned Repository +``` +vim Dockerfile +``` + +The Python application directory structure should now look like the following: +``` +quote_gen +|____ static +|____ templates +|____ app.py +|____ requirements.txt +|____ Dockerfile +``` +``` +quote_disp +|____ static +|____ templates +|____ app.py +|____ requirements.txt +|____ Dockerfile +``` + +Let's create a basic container in each of the directories +``` +FROM python:3.8-slim-buster +COPY . /app +WORKDIR /app +RUN pip install -r requirements.txt +ENTRYPOINT [ "python" ] +CMD [ "app.py" ] +``` + +Let's see what each of these commands means - + +
FROM python - gets a Python distribution from Docker Images
+
WORKDIR Changes the working directory
+
COPY Copies the content of Workdir into a new directory
+ +Build the Docker Images - +``` +cd quote_gen +``` +``` +docker build --tag quote-gen-service . +``` +``` +cd quote_disp +``` +``` +docker build --tag quote-disp-service . +``` + +Run Docker Container + +With the Docker images created, let’s get the containers up and running +``` +cd quote_gen +docker run --name quote-gen-container -p 84:84 quote-gen-service +``` +``` +cd quote_disp +docker run --name quote-disp-container -p 85:85 quote-disp-service +``` + +Let’s run docker container ls to get a list of containers created + +Create Docker Network + +``` +docker network create quote-network +``` +and running the followng command +``` +docker network inspect quote-network +``` + +Let's add our containers to the quote-network + +``` +docker network connect quote-network quote-gen-container +docker network connect quote-network quote-disp-container +docker network inspect quote-network +``` +You see the following output - + +``` +[ + { + "Name": "quote-network", + "Id": "999c81eb87c4b687921ea474abd1e59875447a96d2477ae190dcccc40f882d8a", + "Created": "2023-04-24T04:45:15.9081804Z", + "Scope": "local", + "Driver": "bridge", + "EnableIPv6": false, + "IPAM": { + "Driver": "default", + "Options": {}, + "Config": [ + { + "Subnet": "172.19.0.0/16", + "Gateway": "172.19.0.1" + } + ] + }, + "Internal": false, + "Attachable": false, + "Ingress": false, + "ConfigFrom": { + "Network": "" + }, + "ConfigOnly": false, + "Containers": { + "2636f9d91e5468029981d499fc7e0b46a204d8fc3b16e5e7e6e912651ce8dd4a": { + "Name": "quote-disp-container", + "EndpointID": "a4eb7320b1585b43a10499a73059e8f50fb8d5e33f9aee433b1b7e5e0b1dee85", + "MacAddress": "02:42:ac:13:00:03", + "IPv4Address": "172.19.0.3/16", + "IPv6Address": "" + }, + "557e1ff9f220704ad9f76d94ebe5d3c433dc20ed44798831af6f2bfe68176583": { + "Name": "quote-gen-container", + "EndpointID": "191f2b22ec8a92256d47b152a06eeaeead9f05a13799f48d43d9c5410daceebb", + "MacAddress": "02:42:ac:13:00:02", + "IPv4Address": "172.19.0.2/16", + "IPv6Address": "" + } + }, + "Options": {}, + "Labels": {} + } +] +``` + +Let's see if the dockers are communicating +``` +StatusCode : 200 +StatusDescription : OK +Content : + Docker App Quote +
+
+
+