SlideShare a Scribd company logo
Docker Remote API &
docker-py
Eric Ahn
2016/07
$ docker-machine create -d virtualbox default
$ docker-machine env default
$ docker-machine ls default
$ curl https://192.168.99.100:2376/images/json 
—cert $DOCKER_CERT_PATH/cert.pem 
—key $DOCKER_CERT_PATH/key.pem 
—cacert $DOCKER_CERT_PATH/ca.pem
curl: (58) SSL: Can't load the certificate "/Users/EricAhn/.docker/machine/
machines/default/cert.pem" and its private key: OSStatus -25299
password?
$ cd ~/.docker/machine/machines/default
$ openssl pkcs12 -export 
> -inkey key.pem 
> -in cert.pem 
> -CAfile ca.pem 
> -name client-side 
> -out cert.p12 
> -password pass:mypass
$ curl https://192.168.99.100:2376/images/json 
—cert $DOCKER_CERT_PATH/cert.p12 
—pass mypass 
—key $DOCKER_CERT_PATH/key.pem 
—cacert $DOCKER_CERT_PATH/ca.pem
[{"Id":"sha256:0d409d33b27e47423b049f7f863faa08655a8c901749c2b25b93ca6
7d01a470d","ParentId":"","RepoTags":["nginx:latest"],"RepoDigests":null,"Created":
1464804059,"Size":182786784,"VirtualSize":182786784,"Labels":{}}]
Generate cert.p12
with password
List images :
“nginx:latest”
Result
$ curl -X POST https://192.168.99.100:2376/images/create?fromImage=nginx:latest 
—cert $DOCKER_CERT_PATH/cert.p12 
—pass mypass 
—key $DOCKER_CERT_PATH/key.pem 
—cacert $DOCKER_CERT_PATH/ca.pem
{"status":"Pulling from library/nginx","id":"latest"}
{"status":"Digest:
sha256:0fe6413f3e30fcc5920bc8fa769280975b10b1c26721de956e1428b9e2f29d04"}
{"status":"Status: Image is up to date for nginx:latest"}
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest 0d409d33b27e 7 weeks ago 182.8 MB
Download “nginx:latest” image
Result
Check using command line
$ curl -v -X POST -H "Content-Type: application/json" -d '
{ "Image": "nginx"
}' https://192.168.99.100:2376/containers/create 
--cert $DOCKER_CERT_PATH/cert.p12 
--pass mypass 
--key $DOCKER_CERT_PATH/key.pem 
--cacert $DOCKER_CERT_PATH/ca.pem
{"Id":"8c6e0e97330c08461cdfc179a524ad56c2b0c3a2ba95fc5909a999d
75eb44b37","Warnings":null}
Create container
Result a message
$ curl -X POST -H "Content-Type: application/json" 
> -d '{ "PortBindings": {"80/tcp": [{ "HostPort": "80"}]} }' 
> https://192.168.99.100:2376/containers/8c6e0e97330c/start 
> --cert $DOCKER_CERT_PATH/cert.p12 
> --pass mypass 
> --key $DOCKER_CERT_PATH/key.pem 
> --cacert $DOCKER_CERT_PATH/ca.pem
{"message":"starting container with HostConfig was deprecated
since v1.10 and removed in v1.12"}
Set a specific HostConfig
Result : Failed with
HostConfig
$ curl -v https://192.168.99.100:2376/containers/json?all=1 
--cert $DOCKER_CERT_PATH/cert.p12 
--pass mypass 
--key $DOCKER_CERT_PATH/key.pem 
--cacert $DOCKER_CERT_PATH/ca.pem
[{"Id":"4ee9a6f6b24715266ae8037fd069e2439d67c0198ee8f96b531682d61363f527","Na
mes":["/
hello"],"Image":"nginx:latest","ImageID":"sha256:0d409d33b27e47423b049f7f863faa08655
a8c901749c2b25b93ca67d01a470d","Command":"nginx -g 'daemon off;'","Created":
1469639718,"Ports":[{"PrivatePort":443,"Type":"tcp"},{"IP":"0.0.0.0","PrivatePort":
80,"PublicPort":80,"Type":"tcp"}],"Labels":{},"State":"running","Status":"Up 14
minutes","HostConfig":{"NetworkMode":"default"},"NetworkSettings":{"Networks":{"bridge":
{"IPAMConfig":null,"Links":null,"Aliases":null,"NetworkID":"f22986e826e252df0d0f06011158
9f0a732993c6636ba47e549911ccaf8f8ed8","EndpointID":"41513d5005aa2777561b6c0c
d3f3f6ae44fa7d6d47d261734391e206cdade7b6","Gateway":"172.17.0.1","IPAddress":"17
2.17.0.2","IPPrefixLen":16,"IPv6Gateway":"","GlobalIPv6Address":"","GlobalIPv6PrefixLen":
0,"MacAddress":"02:42:ac:11:00:02"}}},"Mounts":[]}]
List all containers
Result ( json )
$ curl -X POST -H "Content-Type: application/json" 
https://192.168.99.100:2376/containers/8c6e0e97330c/start 
--cert $DOCKER_CERT_PATH/cert.p12 
--pass mypass 
--key $DOCKER_CERT_PATH/key.pem 
--cacert $DOCKER_CERT_PATH/ca.pem
$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
8c6e0e97330c nginx "nginx -g 'daemon off" 2 minutes ago Up 1 seconds 80/tcp, 443/tcp goofy_ardinghelli
Start a container
Running status
$ cd ~/_Python
$ sudo easy_install pip
$ sudo pip install virtualenv
$ virtualenv foobar
$ source foobar/bin/activate
(foobar) $ pip install docker-py
Collecting docker-py
Downloading docker_py-1.9.0-py2.py3-none-any.whl (42kB)
Collecting requests>=2.5.2 (from docker-py)
Downloading requests-2.10.0-py2.py3-none-any.whl (506kB)
100% | | 512kB 938kB/s
Collecting six>=1.4.0 (from docker-py)
Downloading six-1.10.0-py2.py3-none-any.whl
Collecting websocket-client>=0.32.0 (from docker-py)
Downloading websocket_client-0.37.0.tar.gz (194kB)
100% | | 194kB 1.4MB/s
Collecting backports.ssl-match-hostname>=3.5; python_version < "3.5" (from docker-py)
Downloading backports.ssl_match_hostname-3.5.0.1.tar.gz
Building wheels for collected packages: websocket-client, backports.ssl-match-hostname
Running setup.py bdist_wheel for websocket-client ... done
Stored in directory: /Users/EricAhn/Library/Caches/pip/wheels/e4/20/12/48d6732b88733a0a8f98ee1a5b2f59b64b27011d5c34c4f98c
…..
Install python and virtualenv
(foobar) $ vi docker-run.py
import docker
tls_config = docker.tls.TLSConfig(
client_cert=('/Users/EricAhn/.docker/machine/machines/default/cert.pem',
'/Users/EricAhn/.docker/machine/machines/default/key.pem'),
verify='/Users/EricAhn/.docker/machine/machines/default/ca.pem'
)
client = docker.Client(base_url='tcp://192.168.99.100:2376', tls=tls_config)
client.containers()
container_id = client.create_container(
image='nginx:latest',
ports=[80],
name='hello'
)
client.start(
container_id,
port_bindings={80: ('0.0.0.0', 80)}
)
$ python docker-run.py
$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
4ee9a6f6b247 nginx:latest "nginx -g 'daemon off" 2 seconds ago Up 1 seconds 0.0.0.0:80->80/tcp, 443/tcp hello
Python code
Run code and check

More Related Content

What's hot

Securing Prometheus exporters using HashiCorp Vault
Securing Prometheus exporters using HashiCorp VaultSecuring Prometheus exporters using HashiCorp Vault
Securing Prometheus exporters using HashiCorp Vault
Bram Vogelaar
 
How to create your own hack environment
How to create your own hack environmentHow to create your own hack environment
How to create your own hack environment
Sumedt Jitpukdebodin
 
Lessons from running potentially malicious code inside Docker containers
Lessons from running potentially malicious code inside Docker containersLessons from running potentially malicious code inside Docker containers
Lessons from running potentially malicious code inside Docker containers
Ben Hall
 
2012 coscup - Build your PHP application on Heroku
2012 coscup - Build your PHP application on Heroku2012 coscup - Build your PHP application on Heroku
2012 coscup - Build your PHP application on Herokuronnywang_tw
 
Docker, c'est bonheur !
Docker, c'est bonheur !Docker, c'est bonheur !
Docker, c'est bonheur !
Alexandre Salomé
 
Adrian Mouat - Docker Tips and Tricks
 Adrian Mouat - Docker Tips and Tricks Adrian Mouat - Docker Tips and Tricks
Adrian Mouat - Docker Tips and Tricks
Kevin Cross
 
CoreOS + Kubernetes @ All Things Open 2015
CoreOS + Kubernetes @ All Things Open 2015CoreOS + Kubernetes @ All Things Open 2015
CoreOS + Kubernetes @ All Things Open 2015
Brandon Philips
 
Fabric workshop(1) - (MOSG)
Fabric workshop(1) - (MOSG)Fabric workshop(1) - (MOSG)
Fabric workshop(1) - (MOSG)
Soshi Nemoto
 
Preparation study of_docker - (MOSG)
Preparation study of_docker  - (MOSG)Preparation study of_docker  - (MOSG)
Preparation study of_docker - (MOSG)
Soshi Nemoto
 
Testing your infrastructure with litmus
Testing your infrastructure with litmusTesting your infrastructure with litmus
Testing your infrastructure with litmus
Bram Vogelaar
 
Docker in practice
Docker in practiceDocker in practice
Docker in practice
Jonathan Giannuzzi
 
CoreOS: Control Your Fleet
CoreOS: Control Your FleetCoreOS: Control Your Fleet
CoreOS: Control Your Fleet
Matthew Jones
 
Hyperledger composer
Hyperledger composerHyperledger composer
Hyperledger composer
wonyong hwang
 
Ondřej Šika: Docker, Traefik a CI - Mějte nasazené všeny větve na kterých pra...
Ondřej Šika: Docker, Traefik a CI - Mějte nasazené všeny větve na kterých pra...Ondřej Šika: Docker, Traefik a CI - Mějte nasazené všeny větve na kterých pra...
Ondřej Šika: Docker, Traefik a CI - Mějte nasazené všeny větve na kterých pra...
Develcz
 
Nomad + Flatcar: a harmonious marriage of lightweights
Nomad + Flatcar: a harmonious marriage of lightweightsNomad + Flatcar: a harmonious marriage of lightweights
Nomad + Flatcar: a harmonious marriage of lightweights
Iago López Galeiras
 
Vagrant for real (codemotion rome 2016)
Vagrant for real (codemotion rome 2016)Vagrant for real (codemotion rome 2016)
Vagrant for real (codemotion rome 2016)
Michele Orselli
 
Start tracking your ruby infrastructure
Start tracking your ruby infrastructureStart tracking your ruby infrastructure
Start tracking your ruby infrastructure
Sergiy Kukunin
 
Using Nix and Docker as automated deployment solutions
Using Nix and Docker as automated deployment solutionsUsing Nix and Docker as automated deployment solutions
Using Nix and Docker as automated deployment solutions
Sander van der Burg
 
Tensorflow in Docker
Tensorflow in DockerTensorflow in Docker
Tensorflow in Docker
Eric Ahn
 
Deploying Plone and Volto, the Hard Way
Deploying Plone and Volto, the Hard WayDeploying Plone and Volto, the Hard Way
Deploying Plone and Volto, the Hard Way
Asko Soukka
 

What's hot (20)

Securing Prometheus exporters using HashiCorp Vault
Securing Prometheus exporters using HashiCorp VaultSecuring Prometheus exporters using HashiCorp Vault
Securing Prometheus exporters using HashiCorp Vault
 
How to create your own hack environment
How to create your own hack environmentHow to create your own hack environment
How to create your own hack environment
 
Lessons from running potentially malicious code inside Docker containers
Lessons from running potentially malicious code inside Docker containersLessons from running potentially malicious code inside Docker containers
Lessons from running potentially malicious code inside Docker containers
 
2012 coscup - Build your PHP application on Heroku
2012 coscup - Build your PHP application on Heroku2012 coscup - Build your PHP application on Heroku
2012 coscup - Build your PHP application on Heroku
 
Docker, c'est bonheur !
Docker, c'est bonheur !Docker, c'est bonheur !
Docker, c'est bonheur !
 
Adrian Mouat - Docker Tips and Tricks
 Adrian Mouat - Docker Tips and Tricks Adrian Mouat - Docker Tips and Tricks
Adrian Mouat - Docker Tips and Tricks
 
CoreOS + Kubernetes @ All Things Open 2015
CoreOS + Kubernetes @ All Things Open 2015CoreOS + Kubernetes @ All Things Open 2015
CoreOS + Kubernetes @ All Things Open 2015
 
Fabric workshop(1) - (MOSG)
Fabric workshop(1) - (MOSG)Fabric workshop(1) - (MOSG)
Fabric workshop(1) - (MOSG)
 
Preparation study of_docker - (MOSG)
Preparation study of_docker  - (MOSG)Preparation study of_docker  - (MOSG)
Preparation study of_docker - (MOSG)
 
Testing your infrastructure with litmus
Testing your infrastructure with litmusTesting your infrastructure with litmus
Testing your infrastructure with litmus
 
Docker in practice
Docker in practiceDocker in practice
Docker in practice
 
CoreOS: Control Your Fleet
CoreOS: Control Your FleetCoreOS: Control Your Fleet
CoreOS: Control Your Fleet
 
Hyperledger composer
Hyperledger composerHyperledger composer
Hyperledger composer
 
Ondřej Šika: Docker, Traefik a CI - Mějte nasazené všeny větve na kterých pra...
Ondřej Šika: Docker, Traefik a CI - Mějte nasazené všeny větve na kterých pra...Ondřej Šika: Docker, Traefik a CI - Mějte nasazené všeny větve na kterých pra...
Ondřej Šika: Docker, Traefik a CI - Mějte nasazené všeny větve na kterých pra...
 
Nomad + Flatcar: a harmonious marriage of lightweights
Nomad + Flatcar: a harmonious marriage of lightweightsNomad + Flatcar: a harmonious marriage of lightweights
Nomad + Flatcar: a harmonious marriage of lightweights
 
Vagrant for real (codemotion rome 2016)
Vagrant for real (codemotion rome 2016)Vagrant for real (codemotion rome 2016)
Vagrant for real (codemotion rome 2016)
 
Start tracking your ruby infrastructure
Start tracking your ruby infrastructureStart tracking your ruby infrastructure
Start tracking your ruby infrastructure
 
Using Nix and Docker as automated deployment solutions
Using Nix and Docker as automated deployment solutionsUsing Nix and Docker as automated deployment solutions
Using Nix and Docker as automated deployment solutions
 
Tensorflow in Docker
Tensorflow in DockerTensorflow in Docker
Tensorflow in Docker
 
Deploying Plone and Volto, the Hard Way
Deploying Plone and Volto, the Hard WayDeploying Plone and Volto, the Hard Way
Deploying Plone and Volto, the Hard Way
 

Viewers also liked

Py conkr 20150829_docker-python
Py conkr 20150829_docker-pythonPy conkr 20150829_docker-python
Py conkr 20150829_docker-python
Eric Ahn
 
Présentation Ikoula au Meet-up Docker à l'école 42
Présentation Ikoula au Meet-up Docker à l'école 42Présentation Ikoula au Meet-up Docker à l'école 42
Présentation Ikoula au Meet-up Docker à l'école 42
Ikoula
 
Py conkr 20150829_docker-python
Py conkr 20150829_docker-pythonPy conkr 20150829_docker-python
Py conkr 20150829_docker-python
Eric Ahn
 
Http capturing
Http capturingHttp capturing
Http capturing
Eric Ahn
 
High perforance-browse-networking-2015-bwahn
High perforance-browse-networking-2015-bwahnHigh perforance-browse-networking-2015-bwahn
High perforance-browse-networking-2015-bwahn
Eric Ahn
 
Cdn gslb-20151209
Cdn gslb-20151209Cdn gslb-20151209
Cdn gslb-20151209
Eric Ahn
 
Introduction to Tensorflow
Introduction to TensorflowIntroduction to Tensorflow
Introduction to Tensorflow
Tzar Umang
 
Keep it simple web development stack
Keep it simple web development stackKeep it simple web development stack
Keep it simple web development stack
Eric Ahn
 
Docker en production et la sécurité … _
Docker en production   et la sécurité …  _Docker en production   et la sécurité …  _
Docker en production et la sécurité … _
Jean-Marc Meessen
 
Spring rest-doc-2015-11
Spring rest-doc-2015-11Spring rest-doc-2015-11
Spring rest-doc-2015-11
Eric Ahn
 
연구자 및 교육자를 위한 계산 및 분석 플랫폼 설계 - PyCon KR 2015
연구자 및 교육자를 위한 계산 및 분석 플랫폼 설계 - PyCon KR 2015연구자 및 교육자를 위한 계산 및 분석 플랫폼 설계 - PyCon KR 2015
연구자 및 교육자를 위한 계산 및 분석 플랫폼 설계 - PyCon KR 2015
Jeongkyu Shin
 
TensorFlow
TensorFlowTensorFlow
TensorFlow
jirimaterna
 
Introduction to TensorFlow
Introduction to TensorFlowIntroduction to TensorFlow
Introduction to TensorFlow
Matthias Feys
 
Kaz Sato, Evangelist, Google at MLconf ATL 2016
Kaz Sato, Evangelist, Google at MLconf ATL 2016Kaz Sato, Evangelist, Google at MLconf ATL 2016
Kaz Sato, Evangelist, Google at MLconf ATL 2016
MLconf
 
[코세나, kosena] 빅데이터 구축 및 제안 가이드
[코세나, kosena] 빅데이터 구축 및 제안 가이드[코세나, kosena] 빅데이터 구축 및 제안 가이드
[코세나, kosena] 빅데이터 구축 및 제안 가이드
kosena
 
Swift server-side-let swift2016
Swift server-side-let swift2016Swift server-side-let swift2016
Swift server-side-let swift2016
Eric Ahn
 
Advanced Spark and TensorFlow Meetup May 26, 2016
Advanced Spark and TensorFlow Meetup May 26, 2016Advanced Spark and TensorFlow Meetup May 26, 2016
Advanced Spark and TensorFlow Meetup May 26, 2016
Chris Fregly
 
Tensorflow internal
Tensorflow internalTensorflow internal
Tensorflow internal
Hyunghun Cho
 
TensorFlow
TensorFlowTensorFlow
TensorFlow
Sang-Houn Choi
 
Google TensorFlow Tutorial
Google TensorFlow TutorialGoogle TensorFlow Tutorial
Google TensorFlow Tutorial
台灣資料科學年會
 

Viewers also liked (20)

Py conkr 20150829_docker-python
Py conkr 20150829_docker-pythonPy conkr 20150829_docker-python
Py conkr 20150829_docker-python
 
Présentation Ikoula au Meet-up Docker à l'école 42
Présentation Ikoula au Meet-up Docker à l'école 42Présentation Ikoula au Meet-up Docker à l'école 42
Présentation Ikoula au Meet-up Docker à l'école 42
 
Py conkr 20150829_docker-python
Py conkr 20150829_docker-pythonPy conkr 20150829_docker-python
Py conkr 20150829_docker-python
 
Http capturing
Http capturingHttp capturing
Http capturing
 
High perforance-browse-networking-2015-bwahn
High perforance-browse-networking-2015-bwahnHigh perforance-browse-networking-2015-bwahn
High perforance-browse-networking-2015-bwahn
 
Cdn gslb-20151209
Cdn gslb-20151209Cdn gslb-20151209
Cdn gslb-20151209
 
Introduction to Tensorflow
Introduction to TensorflowIntroduction to Tensorflow
Introduction to Tensorflow
 
Keep it simple web development stack
Keep it simple web development stackKeep it simple web development stack
Keep it simple web development stack
 
Docker en production et la sécurité … _
Docker en production   et la sécurité …  _Docker en production   et la sécurité …  _
Docker en production et la sécurité … _
 
Spring rest-doc-2015-11
Spring rest-doc-2015-11Spring rest-doc-2015-11
Spring rest-doc-2015-11
 
연구자 및 교육자를 위한 계산 및 분석 플랫폼 설계 - PyCon KR 2015
연구자 및 교육자를 위한 계산 및 분석 플랫폼 설계 - PyCon KR 2015연구자 및 교육자를 위한 계산 및 분석 플랫폼 설계 - PyCon KR 2015
연구자 및 교육자를 위한 계산 및 분석 플랫폼 설계 - PyCon KR 2015
 
TensorFlow
TensorFlowTensorFlow
TensorFlow
 
Introduction to TensorFlow
Introduction to TensorFlowIntroduction to TensorFlow
Introduction to TensorFlow
 
Kaz Sato, Evangelist, Google at MLconf ATL 2016
Kaz Sato, Evangelist, Google at MLconf ATL 2016Kaz Sato, Evangelist, Google at MLconf ATL 2016
Kaz Sato, Evangelist, Google at MLconf ATL 2016
 
[코세나, kosena] 빅데이터 구축 및 제안 가이드
[코세나, kosena] 빅데이터 구축 및 제안 가이드[코세나, kosena] 빅데이터 구축 및 제안 가이드
[코세나, kosena] 빅데이터 구축 및 제안 가이드
 
Swift server-side-let swift2016
Swift server-side-let swift2016Swift server-side-let swift2016
Swift server-side-let swift2016
 
Advanced Spark and TensorFlow Meetup May 26, 2016
Advanced Spark and TensorFlow Meetup May 26, 2016Advanced Spark and TensorFlow Meetup May 26, 2016
Advanced Spark and TensorFlow Meetup May 26, 2016
 
Tensorflow internal
Tensorflow internalTensorflow internal
Tensorflow internal
 
TensorFlow
TensorFlowTensorFlow
TensorFlow
 
Google TensorFlow Tutorial
Google TensorFlow TutorialGoogle TensorFlow Tutorial
Google TensorFlow Tutorial
 

Similar to Docker remote-api

Docker Registry + Basic Auth
Docker Registry + Basic AuthDocker Registry + Basic Auth
Docker Registry + Basic Auth
Remotty
 
Easy Cloud Native Transformation with Nomad
Easy Cloud Native Transformation with NomadEasy Cloud Native Transformation with Nomad
Easy Cloud Native Transformation with Nomad
Bram Vogelaar
 
Docker, the Future of DevOps
Docker, the Future of DevOpsDocker, the Future of DevOps
Docker, the Future of DevOps
andersjanmyr
 
파이썬 개발환경 구성하기의 끝판왕 - Docker Compose
파이썬 개발환경 구성하기의 끝판왕 - Docker Compose파이썬 개발환경 구성하기의 끝판왕 - Docker Compose
파이썬 개발환경 구성하기의 끝판왕 - Docker Compose
raccoony
 
AWS와 Docker Swarm을 이용한 쉽고 빠른 컨테이너 오케스트레이션 - AWS Summit Seoul 2017
AWS와 Docker Swarm을 이용한 쉽고 빠른 컨테이너 오케스트레이션 - AWS Summit Seoul 2017AWS와 Docker Swarm을 이용한 쉽고 빠른 컨테이너 오케스트레이션 - AWS Summit Seoul 2017
AWS와 Docker Swarm을 이용한 쉽고 빠른 컨테이너 오케스트레이션 - AWS Summit Seoul 2017
Amazon Web Services Korea
 
Presentation iv implementasi 802x eap tls peap mscha pv2
Presentation iv implementasi  802x eap tls peap mscha pv2Presentation iv implementasi  802x eap tls peap mscha pv2
Presentation iv implementasi 802x eap tls peap mscha pv2Hell19
 
Travis and fastlane
Travis and fastlaneTravis and fastlane
Travis and fastlane
Steven Shen
 
Get started with docker &amp; dev ops
Get started with docker &amp; dev opsGet started with docker &amp; dev ops
Get started with docker &amp; dev ops
Asya Dudnik
 
Things I've learned working with Docker Support
Things I've learned working with Docker SupportThings I've learned working with Docker Support
Things I've learned working with Docker Support
Sujay Pillai
 
Delivering Go.CD with Terraform and Docker
Delivering Go.CD with Terraform and DockerDelivering Go.CD with Terraform and Docker
Delivering Go.CD with Terraform and Docker
Jorrit Salverda
 
PHP Backdoor: The rise of the vuln
PHP Backdoor: The rise of the vulnPHP Backdoor: The rise of the vuln
PHP Backdoor: The rise of the vuln
Sandro Zaccarini
 
Railsconf2011 deployment tips_for_slideshare
Railsconf2011 deployment tips_for_slideshareRailsconf2011 deployment tips_for_slideshare
Railsconf2011 deployment tips_for_slidesharetomcopeland
 
Vagrant file samples for various Hadoop distributions
Vagrant file samples for various Hadoop distributionsVagrant file samples for various Hadoop distributions
Vagrant file samples for various Hadoop distributions
Akshay Gore
 
Get started with docker &amp; dev ops
Get started with docker &amp; dev opsGet started with docker &amp; dev ops
Get started with docker &amp; dev ops
Asya Dudnik
 
smartdc by Ruby
smartdc by Rubysmartdc by Ruby
smartdc by Ruby
ogom_
 
Lights, Camera, Docker: Streaming Video at DramaFever
Lights, Camera, Docker: Streaming Video at DramaFeverLights, Camera, Docker: Streaming Video at DramaFever
Lights, Camera, Docker: Streaming Video at DramaFever
bridgetkromhout
 
Going live with BommandBox and docker Into The Box 2018
Going live with BommandBox and docker Into The Box 2018Going live with BommandBox and docker Into The Box 2018
Going live with BommandBox and docker Into The Box 2018
Ortus Solutions, Corp
 
Into The Box 2018 Going live with commandbox and docker
Into The Box 2018 Going live with commandbox and dockerInto The Box 2018 Going live with commandbox and docker
Into The Box 2018 Going live with commandbox and docker
Ortus Solutions, Corp
 
Da APK al Golden Ticket
Da APK al Golden TicketDa APK al Golden Ticket
Da APK al Golden Ticket
Giuseppe Trotta
 

Similar to Docker remote-api (20)

Docker Registry + Basic Auth
Docker Registry + Basic AuthDocker Registry + Basic Auth
Docker Registry + Basic Auth
 
Easy Cloud Native Transformation with Nomad
Easy Cloud Native Transformation with NomadEasy Cloud Native Transformation with Nomad
Easy Cloud Native Transformation with Nomad
 
Docker, the Future of DevOps
Docker, the Future of DevOpsDocker, the Future of DevOps
Docker, the Future of DevOps
 
파이썬 개발환경 구성하기의 끝판왕 - Docker Compose
파이썬 개발환경 구성하기의 끝판왕 - Docker Compose파이썬 개발환경 구성하기의 끝판왕 - Docker Compose
파이썬 개발환경 구성하기의 끝판왕 - Docker Compose
 
AWS와 Docker Swarm을 이용한 쉽고 빠른 컨테이너 오케스트레이션 - AWS Summit Seoul 2017
AWS와 Docker Swarm을 이용한 쉽고 빠른 컨테이너 오케스트레이션 - AWS Summit Seoul 2017AWS와 Docker Swarm을 이용한 쉽고 빠른 컨테이너 오케스트레이션 - AWS Summit Seoul 2017
AWS와 Docker Swarm을 이용한 쉽고 빠른 컨테이너 오케스트레이션 - AWS Summit Seoul 2017
 
Presentation iv implementasi 802x eap tls peap mscha pv2
Presentation iv implementasi  802x eap tls peap mscha pv2Presentation iv implementasi  802x eap tls peap mscha pv2
Presentation iv implementasi 802x eap tls peap mscha pv2
 
Travis and fastlane
Travis and fastlaneTravis and fastlane
Travis and fastlane
 
Get started with docker &amp; dev ops
Get started with docker &amp; dev opsGet started with docker &amp; dev ops
Get started with docker &amp; dev ops
 
Things I've learned working with Docker Support
Things I've learned working with Docker SupportThings I've learned working with Docker Support
Things I've learned working with Docker Support
 
Delivering Go.CD with Terraform and Docker
Delivering Go.CD with Terraform and DockerDelivering Go.CD with Terraform and Docker
Delivering Go.CD with Terraform and Docker
 
PHP Backdoor: The rise of the vuln
PHP Backdoor: The rise of the vulnPHP Backdoor: The rise of the vuln
PHP Backdoor: The rise of the vuln
 
Railsconf2011 deployment tips_for_slideshare
Railsconf2011 deployment tips_for_slideshareRailsconf2011 deployment tips_for_slideshare
Railsconf2011 deployment tips_for_slideshare
 
Vagrant file samples for various Hadoop distributions
Vagrant file samples for various Hadoop distributionsVagrant file samples for various Hadoop distributions
Vagrant file samples for various Hadoop distributions
 
Get started with docker &amp; dev ops
Get started with docker &amp; dev opsGet started with docker &amp; dev ops
Get started with docker &amp; dev ops
 
smartdc by Ruby
smartdc by Rubysmartdc by Ruby
smartdc by Ruby
 
Lights, Camera, Docker: Streaming Video at DramaFever
Lights, Camera, Docker: Streaming Video at DramaFeverLights, Camera, Docker: Streaming Video at DramaFever
Lights, Camera, Docker: Streaming Video at DramaFever
 
Going live with BommandBox and docker Into The Box 2018
Going live with BommandBox and docker Into The Box 2018Going live with BommandBox and docker Into The Box 2018
Going live with BommandBox and docker Into The Box 2018
 
Into The Box 2018 Going live with commandbox and docker
Into The Box 2018 Going live with commandbox and dockerInto The Box 2018 Going live with commandbox and docker
Into The Box 2018 Going live with commandbox and docker
 
EC2
EC2EC2
EC2
 
Da APK al Golden Ticket
Da APK al Golden TicketDa APK al Golden Ticket
Da APK al Golden Ticket
 

Recently uploaded

Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
Alison B. Lowndes
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Product School
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
Fwdays
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
Frank van Harmelen
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Product School
 
Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
Bhaskar Mitra
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
OnBoard
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
Elena Simperl
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Tobias Schneck
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
DianaGray10
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
Product School
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
Paul Groth
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
Product School
 

Recently uploaded (20)

Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
 
Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 

Docker remote-api

  • 1. Docker Remote API & docker-py Eric Ahn 2016/07
  • 2. $ docker-machine create -d virtualbox default $ docker-machine env default $ docker-machine ls default $ curl https://192.168.99.100:2376/images/json —cert $DOCKER_CERT_PATH/cert.pem —key $DOCKER_CERT_PATH/key.pem —cacert $DOCKER_CERT_PATH/ca.pem curl: (58) SSL: Can't load the certificate "/Users/EricAhn/.docker/machine/ machines/default/cert.pem" and its private key: OSStatus -25299 password?
  • 3. $ cd ~/.docker/machine/machines/default $ openssl pkcs12 -export > -inkey key.pem > -in cert.pem > -CAfile ca.pem > -name client-side > -out cert.p12 > -password pass:mypass $ curl https://192.168.99.100:2376/images/json —cert $DOCKER_CERT_PATH/cert.p12 —pass mypass —key $DOCKER_CERT_PATH/key.pem —cacert $DOCKER_CERT_PATH/ca.pem [{"Id":"sha256:0d409d33b27e47423b049f7f863faa08655a8c901749c2b25b93ca6 7d01a470d","ParentId":"","RepoTags":["nginx:latest"],"RepoDigests":null,"Created": 1464804059,"Size":182786784,"VirtualSize":182786784,"Labels":{}}] Generate cert.p12 with password List images : “nginx:latest” Result
  • 4. $ curl -X POST https://192.168.99.100:2376/images/create?fromImage=nginx:latest —cert $DOCKER_CERT_PATH/cert.p12 —pass mypass —key $DOCKER_CERT_PATH/key.pem —cacert $DOCKER_CERT_PATH/ca.pem {"status":"Pulling from library/nginx","id":"latest"} {"status":"Digest: sha256:0fe6413f3e30fcc5920bc8fa769280975b10b1c26721de956e1428b9e2f29d04"} {"status":"Status: Image is up to date for nginx:latest"} $ docker images REPOSITORY TAG IMAGE ID CREATED SIZE nginx latest 0d409d33b27e 7 weeks ago 182.8 MB Download “nginx:latest” image Result Check using command line
  • 5. $ curl -v -X POST -H "Content-Type: application/json" -d ' { "Image": "nginx" }' https://192.168.99.100:2376/containers/create --cert $DOCKER_CERT_PATH/cert.p12 --pass mypass --key $DOCKER_CERT_PATH/key.pem --cacert $DOCKER_CERT_PATH/ca.pem {"Id":"8c6e0e97330c08461cdfc179a524ad56c2b0c3a2ba95fc5909a999d 75eb44b37","Warnings":null} Create container Result a message
  • 6. $ curl -X POST -H "Content-Type: application/json" > -d '{ "PortBindings": {"80/tcp": [{ "HostPort": "80"}]} }' > https://192.168.99.100:2376/containers/8c6e0e97330c/start > --cert $DOCKER_CERT_PATH/cert.p12 > --pass mypass > --key $DOCKER_CERT_PATH/key.pem > --cacert $DOCKER_CERT_PATH/ca.pem {"message":"starting container with HostConfig was deprecated since v1.10 and removed in v1.12"} Set a specific HostConfig Result : Failed with HostConfig
  • 7. $ curl -v https://192.168.99.100:2376/containers/json?all=1 --cert $DOCKER_CERT_PATH/cert.p12 --pass mypass --key $DOCKER_CERT_PATH/key.pem --cacert $DOCKER_CERT_PATH/ca.pem [{"Id":"4ee9a6f6b24715266ae8037fd069e2439d67c0198ee8f96b531682d61363f527","Na mes":["/ hello"],"Image":"nginx:latest","ImageID":"sha256:0d409d33b27e47423b049f7f863faa08655 a8c901749c2b25b93ca67d01a470d","Command":"nginx -g 'daemon off;'","Created": 1469639718,"Ports":[{"PrivatePort":443,"Type":"tcp"},{"IP":"0.0.0.0","PrivatePort": 80,"PublicPort":80,"Type":"tcp"}],"Labels":{},"State":"running","Status":"Up 14 minutes","HostConfig":{"NetworkMode":"default"},"NetworkSettings":{"Networks":{"bridge": {"IPAMConfig":null,"Links":null,"Aliases":null,"NetworkID":"f22986e826e252df0d0f06011158 9f0a732993c6636ba47e549911ccaf8f8ed8","EndpointID":"41513d5005aa2777561b6c0c d3f3f6ae44fa7d6d47d261734391e206cdade7b6","Gateway":"172.17.0.1","IPAddress":"17 2.17.0.2","IPPrefixLen":16,"IPv6Gateway":"","GlobalIPv6Address":"","GlobalIPv6PrefixLen": 0,"MacAddress":"02:42:ac:11:00:02"}}},"Mounts":[]}] List all containers Result ( json )
  • 8. $ curl -X POST -H "Content-Type: application/json" https://192.168.99.100:2376/containers/8c6e0e97330c/start --cert $DOCKER_CERT_PATH/cert.p12 --pass mypass --key $DOCKER_CERT_PATH/key.pem --cacert $DOCKER_CERT_PATH/ca.pem $ docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 8c6e0e97330c nginx "nginx -g 'daemon off" 2 minutes ago Up 1 seconds 80/tcp, 443/tcp goofy_ardinghelli Start a container Running status
  • 9. $ cd ~/_Python $ sudo easy_install pip $ sudo pip install virtualenv $ virtualenv foobar $ source foobar/bin/activate (foobar) $ pip install docker-py Collecting docker-py Downloading docker_py-1.9.0-py2.py3-none-any.whl (42kB) Collecting requests>=2.5.2 (from docker-py) Downloading requests-2.10.0-py2.py3-none-any.whl (506kB) 100% | | 512kB 938kB/s Collecting six>=1.4.0 (from docker-py) Downloading six-1.10.0-py2.py3-none-any.whl Collecting websocket-client>=0.32.0 (from docker-py) Downloading websocket_client-0.37.0.tar.gz (194kB) 100% | | 194kB 1.4MB/s Collecting backports.ssl-match-hostname>=3.5; python_version < "3.5" (from docker-py) Downloading backports.ssl_match_hostname-3.5.0.1.tar.gz Building wheels for collected packages: websocket-client, backports.ssl-match-hostname Running setup.py bdist_wheel for websocket-client ... done Stored in directory: /Users/EricAhn/Library/Caches/pip/wheels/e4/20/12/48d6732b88733a0a8f98ee1a5b2f59b64b27011d5c34c4f98c ….. Install python and virtualenv
  • 10. (foobar) $ vi docker-run.py import docker tls_config = docker.tls.TLSConfig( client_cert=('/Users/EricAhn/.docker/machine/machines/default/cert.pem', '/Users/EricAhn/.docker/machine/machines/default/key.pem'), verify='/Users/EricAhn/.docker/machine/machines/default/ca.pem' ) client = docker.Client(base_url='tcp://192.168.99.100:2376', tls=tls_config) client.containers() container_id = client.create_container( image='nginx:latest', ports=[80], name='hello' ) client.start( container_id, port_bindings={80: ('0.0.0.0', 80)} ) $ python docker-run.py $ docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 4ee9a6f6b247 nginx:latest "nginx -g 'daemon off" 2 seconds ago Up 1 seconds 0.0.0.0:80->80/tcp, 443/tcp hello Python code Run code and check