How to use python Docker Sdk to run container on azure vm?

Expected behavior

I am on a linux environment, want to use python Docker Sdk to run a container on my created azure vm.
I already have a vm on azure, and host is XXX.eastus.cloudapp.azure.com, and I tried

vm_host = "XXX.eastus.cloudapp.azure.com"
client = docker.DockerClient(base_url=f'{vm_host}:8000')
client.login(username=settings.CR_USER_NAME, password=settings.CR_PASSWORD, registry=settings.CR_SERVER)
container = client.containers.run(
                                                  image='imageName',
                                                  detach=True,
                                                  volumes ={'/var/run/docker.sock': {'bind': '/var/run/docker.sock', 'mode': 'rw'}},
                                                  ports={8000 : 8000},
                                                  environment=[f'SQL_DB_HOST={mysql_server_host}','MQTT_BROKER_HOST=XXX.azurecontainer.io',f'CLOUD_HOST={vm_host}:8000'])

I hope it will run a container on my azure vm,

actually I tried almost half day to find which cmd is fit docker -H f’{vm_host}', I guess it’s base_url? I have survey hours on docker-sdk document but I still don’t know how to set daemon socks connect to.

Actual behavior

but I still got Error: Error while fetching server API version: HTTPConnectionPool

Additional Information

use linux, python3.6

Steps to reproduce the behavior

  1. maybe it’s hard to reproduce the behavior? I just want to know how to use python docker-sdk to set host which cause the same effect as docker cli docker run -H <vm_host>
    thanks for everyone who finish reading my question

I resolved it, finally…
And I write a note on hackmd, hope to help someone else~
https://hackmd.io/L2hyHRTTTsKGLhJpBiQyiw?view