Skip to content

Instantly share code, notes, and snippets.

@ltupin
Last active August 30, 2018 11:43
Show Gist options
  • Save ltupin/c459b2080b8120f6401e87f84db625d9 to your computer and use it in GitHub Desktop.
Save ltupin/c459b2080b8120f6401e87f84db625d9 to your computer and use it in GitHub Desktop.
Using docker API with python SDK

Using docker API with python SDK https://docker-py.readthedocs.io/en/stable

import docker
client = docker.from_env()
client.containers.run('alpine', 'echo hello world')

import docker
client = docker.from_env()
client.containers.create(image='jupyterhub-notebook-gpu-nvidia:stable', command='', runtime='nvidia')
import docker
import os
cert_path = "..."
tls_config = docker.tls.TLSConfig(
    client_cert=(os.path.join(cert_path, 'cert.pem'),
                 os.path.join(cert_path, 'key.pem')),
    ca_cert=os.path.join(cert_path, 'ca.pem'),
    verify=True,
    assert_hostname=False,
)
client = docker.DockerClient(base_url="https://192.168.99.100:2376", tls=tls_config)
containers = client.containers.list()
python3 - <<EOF
import docker
client = docker.from_env()
client.containers.create(image='jupyterhub-notebook-gpu-nvidia:stable', command='', runtime='nvidia')
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment