[Python] Docker-mounted folder appears empty inside Flask backend container causing...

Discussão em 'Python' iniciado por Stack, Junho 21, 2025.

  1. Stack

    Stack Membro Participativo

    I'm developing a Flask backend running inside a Docker container. My backend needs to process medical DICOM files located on the host machine in a folder like /host/path/runs/container_1/input. I mounted the volume on docker via docker-compose.yml. I work with medical AI-Container which is pure input-output based CLI Container which operates in . It works prefectly when i use docker bash commands to make it do what it is supposed to but when i test the same function via API it doesnt find any Files in input folder. The API code i attached works but is very very hardcoded and i need to make it universal for different devices and different OS like Linux and Windows. Thanks !

    @api_blueprint.route("/analyze_dicom/<int:container_id>", methods=["POST"])
    def analyze_dicom(container_id):
    container = Container.query.get(container_id)
    if not container:
    return jsonify({"error": "Container not found"}), 404

    #Hardcoded host path (real Windows path)
    base_host_path = PureWindowsPath(f"C:/mraay/mRayAIR_MEP_2025/container_manager/app/runs")
    input_dir = base_host_path / f"container_{container_id}" / "input"
    output_dir = base_host_path / f"container_{container_id}" / "output"

    try:
    result = run([
    "docker", "run", "--rm",
    "--ipc=host",
    "--ulimit", "memlock=-1",
    "--ulimit", "stack=67108864",
    "-v", f"{input_dir}:/data:ro",
    "-v", f"{output_dir}:/output",
    container.image,
    "bash", "-c",
    "echo 'Inside container: /data'; ls -l /data; echo '---'; TotalSegmentator -i /data -o /output --fast --verbose"
    ],
    check=True,
    capture_output=True,
    text=True)

    return jsonify({
    "message": f"Analysis successful for container {container_id}",
    "input_used": str(input_dir),
    "output_created": str(output_dir),
    "returncode": result.returncode,
    "stdout": result.stdout,
    "stderr": result.stderr
    }), 200

    except CalledProcessError as e:
    return jsonify({
    "error": "Container execution failed",
    "details": str(e),
    "stdout": e.stdout,
    "stderr": e.stderr
    }), 500**

    Continue reading...

Compartilhe esta Página