Is it possible, using the docker SDK for Python, to launch a container in a remote machine?
import docker
client = docker.from_env()
client.containers.run("bfirsh/reticulate-splines", detach=True)
# I'd like to run this container ^^^ in a machine that I have ssh access to.
Going through the documentation it seems like this type of management is out of scope for said SDK, so searching online I got hints that the kubernetes client for Python could be of help, but don’t know where to begin.
3
Answers
It’s possible, simply do this:
Here’s the document I found related to this:
https://docker-py.readthedocs.io/en/stable/client.html#client-reference
If you only have SSH access to it, there is an
use_ssh_client
optionIt’s not clearly documented by Docker SDK for Python, but you can use SSH to connect to Docker daemon by specifying host with
ssh://[user]@[host]
format, for example:It’s also possible to set environment variable
DOCKER_HOST=ssh://username@your_host
and use the example your provided which use current environment to create client, for example:Note: as specified in the question, this is considering you have SSH access to target host. You can test with
If you have a k8s cluster, you do not need the Python sdk. You only need the cmd line tool kubectl.
Once you have it installed, you can create a deployment that will deploy your image.