29 lines
692 B
Python
29 lines
692 B
Python
|
|
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)
|
|
|
|
|