Docker Community Forums

Share and learn in the Docker community.

Using opencv and python only successful when called from Command Line in container

Hi there,

I am having an issue calling a python file script that uses opencv-python libs.
When i docker exec -it image-id /bin/bash into the container, then call python script everything works fine.

However when i call the python script either directly with a CMD command from the Dockerfile or with .sh script via an ENTRYPOINT command, i get a failure. Even when i set the shebang of the .sh script to /bin/bash

The error comes from opencv. I have posted in their forum for some help, but I am wondering what differences there are in the calling structure/mechanism when calling the scripts in the difference ways i have outlined above, using CMD or .sh script via ENTRYPOINT

As far as i can tell docker will runs something like /bin/sh -c "run this command"

I have no idea why this might be happening and any ideas are welcome.

Thanks in advance,
Wilson

If you don’t have Flask already installed, it’s easy to do so with a single command:

$ pip install flask
After Flask has been installed, create a project folder, named FlaskApp for an example. In this folder, create a base file, named something like app.py.

Within app.py import the Flask module and create a web app using the following:

from flask import Flask

app = Flask(name)`
Next, let’s define the basic route / and the corresponding request handler:

@app.route("/")
def index():
return “”"

Python Flask in Docker!

A sample web-app for running Flask inside Docker.

""" Finally, let's launch the app if the script is invoked as the main program:

if name == “main”:
app.run(debug=True, host=‘0.0.0.0’)
$ python3 app.py
Navigate your browser to http://localhost:5000/. You should be prompted with the “Dockerzing Python app using Flask” message!