Flask container not able to communicate with the localhost command line in order to send requests and retrieve responses

The first issue concerns a Flask container that is available inside a Docker Compose environment. The goal is to make the Flask container able to communicate with the localhost command line in order to send requests and retrieve responses. Specifically, we are using Python’s os.popen method to send parameters to the C# code, execute it, and then retrieve the response. An example of this can be found below:

pi_system_data=os.popen(f"C:\Users\NVTC\source\repos\TagValues4\bin\Debug\TagValues.exe “{str_pi}” “{mindate}” “{maxdate}” “{period}” ")

pi_system_data= pi_system_data.read()

As we are planning to move this project to a Docker Compose environment, we need to find a way for the Python script to still be able to interact with the localhost command line in order to execute the C# code.

The second issue is related to certain packages that I am using in the project. Specifically, I am having trouble with the pynput package, which is mainly used to mimic keyboard clicks in the system. The package works fine when running in Windows, but when I move it to the Docker Compose environment, I am encountering some issues. Kindly find below the package code that is causing the issue:

from pynput import keyboard as keyb

When I comment out the import code and other related code for this package, the system works fine. However, when the pynput package is included, I am encountering the error as shown in the screenshot attached.

image.png

I would greatly appreciate any guidance or suggestions you may have on how to resolve these issues. Please let me know if you need any additional information or if there is anything else I can provide to assist in resolving these issues.

You need to decide if you want to run something in a container or on the host. There is no such thing as running a script from the container on the host outside the container. It wouldn’t make sense since you are using a container to isolate the processes from the host.

Since you mentioned Windows, I guess you are using Docker Desktop. In that case your environment is not just a “Docker Compose environment”. Docker Desktop runs a virtual machine and everything will run in that VM.

You probably need to redesign your software to run an API server on the host and call that API from the container so the host can execute commands if it needs to.

About pyinput: I don’t know how that works, but if it worked on Windows it doesn’t mean it will work on Linux. Docker Desktop can run Windows containers and Linux containers too, but using Linux containers is more common than Windows containers. Which are you using?

If the answer is Linux containers and it supports Linux, Docker Desktop could still be a problem since python is running in the VM too without accessing events on your host.