A
This commit is contained in:
commit
84bbbc17d7
2 changed files with 36 additions and 0 deletions
7
Dockerfile
Normal file
7
Dockerfile
Normal file
|
@ -0,0 +1,7 @@
|
|||
FROM ubuntu
|
||||
RUN apt-get update -y
|
||||
RUN apt install wget -y
|
||||
RUN apt install python3 -y
|
||||
RUN apt install python3-pip -y
|
||||
RUN pip3 install flask
|
||||
RUN wget etud.insa-toulouse.fr/~benassai/microservice.py
|
29
mainserver.py
Normal file
29
mainserver.py
Normal file
|
@ -0,0 +1,29 @@
|
|||
|
||||
from flask import Flask, jsonify
|
||||
import docker
|
||||
app = Flask(__name__)
|
||||
|
||||
@app.route('/', methods = ['GET'])
|
||||
def getMessages():
|
||||
|
||||
return "Hello word"
|
||||
|
||||
@app.route('/newContainer', methods = ['GET'])
|
||||
def createContainer():
|
||||
client = docker.from_env()
|
||||
cont = client.containers.run(image = "app:proxy", ports={5000:50001}, name = 'proxy', command="python3 ./microservice.py", detach = True)
|
||||
return "Success"
|
||||
|
||||
@app.route('/delContainer', methods = ['GET'])
|
||||
def deleteContainer():
|
||||
client = docker.from_env()
|
||||
for c in client.containers.list():
|
||||
c.stop()
|
||||
client.containers.prune()
|
||||
return "Success"
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
app.run(host="0.0.0.0",port=50000)
|
||||
|
||||
|
Loading…
Reference in a new issue