docker / docker-py

A Python library for the Docker Engine API
https://docker-py.readthedocs.io/
Apache License 2.0
6.78k stars 1.67k forks source link

PyPI - docker Integration in Flask app #3272

Open irtaza9 opened 2 months ago

irtaza9 commented 2 months ago

I am playing with docker sdk for python in the flask app. But I am facing some errors while using it. I think doc's should add the usage area for flask framework.

from flask import Flask
import docker

app = Flask(__name__)

@app.route("/")
def getAllAvailableImages():
    client = docker.APIClient()
    client = client.from_env()
    api = client.api
    for image in api.images.list():
        print(image.id)

(.venv) ➜ kasm-streaming flask --app app run Usage: flask run [OPTIONS] Try 'flask run --help' for help.

Error: While importing 'app', an ImportError was raised:

Traceback (most recent call last):
  File "/Users/irtaza/Desktop/Developer/Ideas/ondemand/kasm-streaming/.venv/lib/python3.12/site-packages/flask/cli.py", line 245, in locate_app
    __import__(module_name)
  File "/Users/irtaza/Desktop/Developer/Ideas/ondemand/kasm-streaming/app.py", line 2, in <module>
    import docker
ModuleNotFoundError: No module named 'docker'
Khushiyant commented 6 days ago

I can't seem to get what's problem here, other than docker not installed/found