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

CSE3035 LAB DA2: Submitted By: Abhishek Kandel (19BCE2629)

1. The document describes configuring a nested virtual machine with a container inside another VM on a local machine. 2. It includes steps to build a Docker image, run an app in the image using port mapping, push the image to Docker Hub, and create a MySQL table. 3. The document provides code for a Python Flask app using MySQL to register and log in users on index, login, and register templates.

Uploaded by

theonlygod
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)
37 views12 pages

CSE3035 LAB DA2: Submitted By: Abhishek Kandel (19BCE2629)

1. The document describes configuring a nested virtual machine with a container inside another VM on a local machine. 2. It includes steps to build a Docker image, run an app in the image using port mapping, push the image to Docker Hub, and create a MySQL table. 3. The document provides code for a Python Flask app using MySQL to register and log in users on index, login, and register templates.

Uploaded by

theonlygod
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
You are on page 1/ 12

Submitted by: Abhishek Kandel(19BCE2629)

CSE3035 LAB DA2

Configure a Nested Virtual Machine (Container under another VM) in Local Machine

1. Building an Image

Docker login:

Dockerfile:
App.py
2. Running an app in the image (with container IP address)

3. Pushing the Image to Docker hub


4.removal of image

5. PORT MAPPING: Running an app in the image (with host IP address)


Mysql table creation:

Tried to install flask-mysqldb


Tried to install flask-mysqldb in python virtual environment:

App.py
from flask import Flask, render_template, request, redirect, url_for,
session
from flask_mysqldb import MySQL
import MySQLdb.cursors
import re

app = Flask(__name__)

app.secret_key = '1234321'

app.config['MYSQL_HOST'] = 'localhost'
app.config['MYSQL_USER'] = 'root'
app.config['MYSQL_PASSWORD'] = 'welcome123'
app.config['MYSQL_DB'] = 'pythonlogin'

mysql = MySQL(app)

@app.route('/')
@app.route('/login', methods =['GET', 'POST'])
def login():
msg = ''
if request.method == 'POST' and 'username' in request.form and
'password' in request.form:
username = request.form['username']
password = request.form['password']
cursor = mysql.connection.cursor(MySQLdb.cursors.DictCursor)
cursor.execute('SELECT * FROM accounts WHERE username = % s AND
password = % s', (username, password, ))
account = cursor.fetchone()
if account:
session['loggedin'] = True
session['id'] = account['id']
session['username'] = account['username']
msg = 'Logged in successfully !'
return render_template('index.html', msg = msg)
else:
msg = 'Incorrect username / password !'
return render_template('login.html', msg = msg)

@app.route('/logout')
def logout():
session.pop('loggedin', None)
session.pop('id', None)
session.pop('username', None)
return redirect(url_for('login'))

@app.route('/register', methods =['GET', 'POST'])


def register():
msg = ''
if request.method == 'POST' and 'username' in request.form and
'password' in request.form and 'email' in request.form :
username = request.form['username']
password = request.form['password']
email = request.form['email']
cursor = mysql.connection.cursor(MySQLdb.cursors.DictCursor)
cursor.execute('SELECT * FROM accounts WHERE username = % s',
(username, ))
account = cursor.fetchone()
if account:
msg = 'Account already exists !'
elif not re.match(r'[^@]+@[^@]+\.[^@]+', email):
msg = 'Invalid email address !'
elif not re.match(r'[A-Za-z0-9]+', username):
msg = 'Username must contain only characters and numbers !'
elif not username or not password or not email:
msg = 'Please fill out the form !'
else:
cursor.execute('INSERT INTO accounts VALUES (NULL, % s, % s, %
s)', (username, password, email, ))
mysql.connection.commit()
msg = 'You have successfully registered !'
elif request.method == 'POST':
msg = 'Please fill out the form !'
return render_template('register.html', msg = msg)

Index.html
<html>

<head>

<meta charset="UTF-8">

<title> Index </title>

<link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}">

</head>

<body></br></br></br></br></br>

<div align="center">

<div align="center" class="border">

<div class="header">

<h1 class="word">Index</h1>

</div></br></br></br>

<h1 class="bottom">

Hi {{session.username}}!!</br></br> Welcome to the index page 19BCE2629

</h1></br></br></br>
<a href="{{ url_for('logout') }}" class="btn">Logout</a>

</div>

</div>

</body>

</html>

Login.html
<html>
<head>
<meta charset="UTF-8">
<title> Login </title>
<link rel="stylesheet" href="{{ url_for('static',
filename='style.css') }}">
</head>
<body></br></br></br></br></br>
<div align="center">
<div align="center" class="border">
<div class="header">
<h1 class="word">Login</h1>
</div></br></br></br>
<h2 class="word">
<form action="{{ url_for('login') }}" method="post">
<div class="ABHISHEK 19BCE2629">{{ msg }}</div>
<input id="username" name="username" type="text"
placeholder="Enter Your Username" class="textbox"/></br></br>
<input id="password" name="password" type="password"
placeholder="Enter Your Password" class="textbox"/></br></br></br>
<input type="submit" class="btn" value="Sign
In"></br></br>
</form>
</h2>
<p class="bottom">Dont't have an account? <a class="bottom"
href="{{url_for('register')}}"> Sign Up here</a></p>
</div>
</div>
</body>
</html>

Register.html
<html>
<head>
<meta charset="UTF-8">
<title> Register </title>
<link rel="stylesheet" href="{{ url_for('static',
filename='style.css') }}">
</head>
<body></br></br></br></br></br>
<div align="center">
<div align="center" class="border">
<div class="header">
<h1 class="word">Register</h1>
</div></br></br></br>
<h2 class="word">
<form action="{{ url_for('register') }}" method="post">
<div class="ABHISHEK 19BCE2629">{{ msg }}</div>
<input id="username" name="username" type="text"
placeholder="Enter Your Username" class="textbox"/></br></br>
<input id="password" name="password" type="password"
placeholder="Enter Your Password" class="textbox"/></br></br>
<input id="email" name="email" type="text"
placeholder="Enter Your Email ID" class="textbox"/></br></br>
<input type="submit" class="btn" value="Sign Up"></br>
</form>
</h2>
<p class="bottom">Already have an account? <a class="bottom"
href="{{url_for('login')}}"> Sign In here</a></p>
</div>
</div>
</body>
</html>
https://drive.google.com/drive/folders/1ROtQJqG3UYf-Yl2qJunlGsgan7f0npK8?usp=sharing

THANK YOU!!!

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy