superchatai commited on
Commit
8363c57
·
verified ·
1 Parent(s): e8bd9fe

Update lib.py

Browse files
Files changed (1) hide show
  1. lib.py +35 -7
lib.py CHANGED
@@ -595,20 +595,48 @@ if FLASK_AVAILABLE:
595
  vm_id = str(uuid.uuid4())[:8]
596
  container_name = f"vm-{vm_id}"
597
 
598
- # Create and start container
599
  success, stdout, stderr = run_podman_cmd([
600
  'run', '-d', '--name', container_name,
601
  '--cpus', str(vcpu), '--memory', memory,
602
  '--rm', image, 'sleep', 'infinity'
603
  ])
604
 
 
605
  if not success:
606
- print(f"Failed to create container: {stderr}")
607
- if "authentication required" in stderr.lower():
608
- print("Podman authentication issue. Try running: podman login docker.io")
609
- elif "podman not found" in stderr.lower():
610
- print("Podman not installed. Install with: sudo apt install podman")
611
- return None
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
612
 
613
  self.vms[vm_id] = {
614
  'container_name': container_name,
 
595
  vm_id = str(uuid.uuid4())[:8]
596
  container_name = f"vm-{vm_id}"
597
 
598
+ # Try different container creation approaches for different environments
599
  success, stdout, stderr = run_podman_cmd([
600
  'run', '-d', '--name', container_name,
601
  '--cpus', str(vcpu), '--memory', memory,
602
  '--rm', image, 'sleep', 'infinity'
603
  ])
604
 
605
+ # If rootless podman fails, try with different options
606
  if not success:
607
+ print(f"Initial container creation failed: {stderr}")
608
+
609
+ # Check if we're in a containerized environment
610
+ if os.path.exists('/.dockerenv') or os.path.exists('/run/.containerenv'):
611
+ print("Detected containerized environment, trying alternative podman configuration...")
612
+
613
+ # Try with --privileged flag for podman
614
+ success, stdout, stderr = run_podman_cmd([
615
+ '--runtime', 'runc', 'run', '-d', '--name', container_name,
616
+ '--cpus', str(vcpu), '--memory', memory,
617
+ '--rm', image, 'sleep', 'infinity'
618
+ ])
619
+
620
+ if not success:
621
+ # Try with crun runtime if available
622
+ success, stdout, stderr = run_podman_cmd([
623
+ '--runtime', 'crun', 'run', '-d', '--name', container_name,
624
+ '--cpus', str(vcpu), '--memory', memory,
625
+ '--rm', image, 'sleep', 'infinity'
626
+ ])
627
+
628
+ if not success:
629
+ print(f"Failed to create container after retries: {stderr}")
630
+ if "authentication required" in stderr.lower():
631
+ print("Podman authentication issue. Try running: podman login docker.io")
632
+ elif "podman not found" in stderr.lower():
633
+ print("Podman not installed. Install with: sudo apt install podman")
634
+ elif "namespace" in stderr.lower() or "newuidmap" in stderr.lower():
635
+ print("Rootless podman issue. Container needs privileged mode or proper user namespace setup.")
636
+ print("Try running container with: --privileged --cap-add=SYS_ADMIN")
637
+ elif "shared mount" in stderr.lower():
638
+ print("Mount sharing issue. Try running container with: --mount type=tmpfs,destination=/tmp")
639
+ return None
640
 
641
  self.vms[vm_id] = {
642
  'container_name': container_name,