SubrataSarkar32 / local-flask-forward-proxy

local flask proxy
Apache License 2.0
1 stars 0 forks source link

Great job,but some time not work #1

Open dearvcc opened 4 months ago

dearvcc commented 4 months ago

I try this to forward a docker request from local docker client to a remote docker engine such as : tcp://remote:2375,some simple command work,such as: docker -H localhost ps docker -H localhost version but many complicated command don't,such as: docker -H localhost exec container-name ls it response nothing,the debug output looks like below:

image

If we directly access the remote Docker engine using the the command below,the response is ok:

docker -H remote exec container-name ls

I have no idea how to improve it,maybe you can help me,thank you very much!

SubrataSarkar32 commented 4 months ago

In the function forward_request https://github.com/SubrataSarkar32/local-flask-forward-proxy/blob/eb84c3faa8687d34ed50151c77b9f6ad308d3390/local_flask_proxy_all.py#L63

You can add a check for json parsable output and format and print it if you want

Sample code to be inserted after https://github.com/SubrataSarkar32/local-flask-forward-proxy/blob/eb84c3faa8687d34ed50151c77b9f6ad308d3390/local_flask_proxy_all.py#L74

if response.headers.get('content-type') == 'application/json':
    print(response.json())

You can then parse this json data and output only the required values. You can try running this and let me know if you are getting your desired output.

dearvcc commented 4 months ago

In the function forward_request

https://github.com/SubrataSarkar32/local-flask-forward-proxy/blob/eb84c3faa8687d34ed50151c77b9f6ad308d3390/local_flask_proxy_all.py#L63

You can add a check for json parsable output and format and print it if you want

Sample code to be inserted after

https://github.com/SubrataSarkar32/local-flask-forward-proxy/blob/eb84c3faa8687d34ed50151c77b9f6ad308d3390/local_flask_proxy_all.py#L74

if response.headers.get('content-type') == 'application/json':
    print(response.json())

You can then parse this json data and output only the required values. You can try running this and let me know if you are getting your desired output.

I have tried,furthermore, I traced many times,I think maybe not involved with json format. As if simple requests such as "docker ps,docker version" responsing json data format,but complicated requests will addtional use application/vnd.docker.raw-stream format.

I suggest you to install a Docker instance th have a try. Docker can be configed to expose a TCP port (2375) for remotely operating by RESTful APIs.The regular usage is:

docker -H docer-server-name-or-ip version

The default port(2375) can be omitted. And now,we will do the same thing by you proxy code,like this, to pretend that we run them on the same machine:

docker -H localhost:5000 version I modify your code to adapt this:

target_url_with_path = f'http://va:2375/{subpath}' ... target_url = f'http://va:2375/{subpath.split("/")[0]}'

Herer "va" is the host which the Docker server engine is running.

Above is my test platform.

Thanks a million for your response!