Skip to content

Commit d2ef1fe

Browse files
authored
Add files via upload
1 parent 827cc8f commit d2ef1fe

File tree

5 files changed

+47
-0
lines changed

5 files changed

+47
-0
lines changed

app/backend/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
flask

app/backend/server.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from flask import Flask, request, jsonify
2+
import subprocess
3+
4+
app = Flask(__name__)
5+
6+
@app.route('/api/docker/<action>', methods=['POST'])
7+
def manage_docker(action):
8+
try:
9+
if action == 'start':
10+
# Example: Run a container
11+
subprocess.run(['docker', 'run', '-d', '--name', 'example', 'nginx'], check=True)
12+
return jsonify({"message": "Container started!"})
13+
elif action == 'stop':
14+
# Example: Stop a container
15+
subprocess.run(['docker', 'stop', 'example'], check=True)
16+
subprocess.run(['docker', 'rm', 'example'], check=True)
17+
return jsonify({"message": "Container stopped and removed!"})
18+
else:
19+
return jsonify({"message": "Invalid action"}), 400
20+
except subprocess.CalledProcessError as e:
21+
return jsonify({"message": f"Error: {e}"}), 500
22+
23+
if __name__ == '__main__':
24+
app.run(host='0.0.0.0', port=8082)

app/frontend/index.html

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<title>Docker Manager</title>
5+
<link rel="stylesheet" href="styles.css">
6+
</head>
7+
<body>
8+
<p lang="en">
9+
<h1>Docker Manager</h1>
10+
<button onclick="manageDocker('start')">Start Container</button>
11+
<button onclick="manageDocker('stop')">Stop Container</button>
12+
<script src="script.js"></script>
13+
</body>
14+
</html>
15+

app/frontend/script.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
function manageDocker(action) {
2+
fetch(`/api/docker/${action}`, { method: 'POST' })
3+
.then(response => response.json())
4+
.then(data => alert(data.message))
5+
.catch(error => console.error('Error:', error));
6+
}
7+

app/frontend/styles.css

Whitespace-only changes.

0 commit comments

Comments
 (0)