0% found this document useful (0 votes)
9 views12 pages

Sample Solution

The document outlines a practical exam for building a sample web application using Flask within a Docker container. It details the steps taken by the student, Lohitha Repalle, including setting up the environment, writing the application code, creating a Dockerfile, and running the application in a container. The process involves using Oracle VirtualBox, Ubuntu OS, and various terminal commands to verify the application's functionality.

Uploaded by

Charan Gudavalli
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views12 pages

Sample Solution

The document outlines a practical exam for building a sample web application using Flask within a Docker container. It details the steps taken by the student, Lohitha Repalle, including setting up the environment, writing the application code, creating a Dockerfile, and running the application in a container. The process involves using Oracle VirtualBox, Ubuntu OS, and various terminal commands to verify the application's functionality.

Uploaded by

Charan Gudavalli
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

CISCO DEVNET ASSOCIATE PRACTICAL EXAM

Name : Lohitha Repalle


Roll No : 208W1A05B1
Class : ¾ B Tech, CSE-B
Topic : Build a Sample Web App in a Docker Container
Tools used : Oracle VirtualBox Manager, Ubuntu OS (guest machine) ,
Windows OS (Host), Ubuntu Terminal, Flash web application framework
System Screenshots:

Ipconfig /all:
Oracle VM VirtualBox Manager

After loading and starting DEVASC-LABVM from VirtualBox Manager


Terminal in DEVASC - LABVM

Creating a Sample Web App in a Docker Container


1. Install Flask and open a port on the DEVASC VM firewall.
2. Open the sample_app.py file and add commands
Commands:
from flask import Flask
from flask import request
sample = Flask(__name__)
@[Link]("/")
def main():
return "You are calling me from " + request.remote_addr + "\n"
if __name__ == "__main__":
[Link](host="[Link]", port=8080)
3. Save and run the sample web app and verify it in Chromium web browser
4. Configure the Web App to use Website Files

Update the python code (sample_app.py) as follows


5. Save and run the script
Verify it one of the two ways:
[Link] web browser
[Link] curl command in another terminal- curl [Link]
6. Create a Bash script to build and run a docker container
[Link]
#!/bin/bash
mkdir tempdir
mkdir tempdir/templates
mkdir tempdir/static
cp sample_app.py tempdir/.
cp -r templates/* tempdir/templates/.
cp -r static/* tempdir/static/.
echo "FROM python" > tempdir/Dockerfile
echo "RUN pip install flask" >> tempdir/Dockerfile
echo "COPY ./static /home/myapp/static/" >> tempdir/Dockerfile
echo "COPY ./templates /home/myapp/templates/" >> tempdir/Dockerfile
echo "COPY sample_app.py /home/myapp/" >> tempdir/Dockerfile
echo "EXPOSE 8080" >> tempdir/Dockerfile
echo "CMD python3 /home/myapp/sample_app.py" >> tempdir/Dockerfile
cd tempdir
docker build -t sampleapp .
docker run -t -d -p 8080:8080 --name samplerunning sampleapp
docker ps -a
7. Build, run and verify the Docker container

Execute bash script


Investigate the running docker and the web app
8. Access and explore the running container

9. Stop and remove the docker container

You might also like