-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_docker.py
More file actions
51 lines (42 loc) · 1.6 KB
/
run_docker.py
File metadata and controls
51 lines (42 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env python3
"""
Docker Runner for Text Classification API
Build and run the API using Docker
"""
import subprocess
import sys
import os
def main():
"""Run the Text Classification API with Docker"""
print("🐳 Starting Text Classification API with Docker...")
# Check if docker-compose.yml exists in api folder
api_dir = os.path.join(os.path.dirname(__file__), "api")
docker_compose_path = os.path.join(api_dir, "docker-compose.yml")
if not os.path.exists(docker_compose_path):
print("❌ docker-compose.yml not found in api directory!")
sys.exit(1)
# Change to api directory for docker-compose commands
os.chdir(api_dir)
try:
# Build and start the services
print("🔨 Building Docker images...")
subprocess.run(["docker-compose", "build"], check=True)
print("🚀 Starting Docker containers...")
print("📡 API will be available at: http://localhost:8000")
print("📖 API documentation: http://localhost:8000/docs")
print("🔍 Health check: http://localhost:8000/health")
print("Press Ctrl+C to stop the containers")
print("-" * 50)
subprocess.run(["docker-compose", "up"], check=True)
except KeyboardInterrupt:
print("\n🛑 Stopping Docker containers...")
try:
subprocess.run(["docker-compose", "down"], check=False)
except:
pass
print("👋 Docker containers stopped")
except subprocess.CalledProcessError as e:
print(f"❌ Docker command failed: {e}")
sys.exit(1)
if __name__ == "__main__":
main()