docker and python - mjbright.github.io€¦ · what "standard" images exist on the docker...
TRANSCRIPT
DockerandPython
@mjbright
3juillet2017,RMLLSt-Etienne,MichaelBright
Agenda
RunningPythonappsunderDocker
TheDockerAPI
Docker-machinefromPython
docker-py:ControllingDockerfromPython
OtherModules
AnsibleContainer
@mjbright
OfcoursewecanrunanyappunderDocker-Pythonornot.
Thiscanbeaveryusefulalternativetovirtualenv
RunningPythonappsunderDocker
completefilesystemisolationallowingtohavecomplexdependanciesbeyondPythonitself
launchmultipleinstancesofaPythonprocessinisolation
isolatedfilesystem,processspace,ports
pullexistingimagesofapplications,frameworks
builduponexistingimagesandpushtheresultstoshare
cancomposecomplexapplicationsfrommultiplecontainers
@mjbright
What"standard"imagesexistontheDockerHub?hub.docker.com
RunningPythonappsunderDocker-2
Python:"python"
small,largebaseimages
basedonDebian,Alpine(&evenWindowsServerCore!)
Python2.x[2.7.13],3.x[3.3.6,3.4.6,3.5.3,3.6.1,3.6.2rc1]
Frameworks:
Flask
Cherrypy
Django
...
@mjbright
Let'stakealookathowthedockercommand-lineclientmakesuseofthedockerAPItoperformrequests
Canwemakeourowncommand-linerequestsusingcurl?
TheDockerAPI
@mjbright
Therearemanydocker-relatedmodulesavailableinPython.
Let'sfirstlookat"docker-machine"whichprovidesasimple-*encapsulationaroundthedocker-machineexecutable.
*-abittoosimple:ifdocker-machineissuesapromptyouwillnotbeinformed(problemwithAzurelogin).
NeverthelessitprovidesanicewrapperenablingtosimplyfireupDockerhostsandpasstheirconfigtothedocker-pyclient.
Docker-machinefromPython
@mjbright
Installingthemodule:
Fromlocalrepo(modifiedtoworkwithdocker-pyv2)
gitclonehttps://github.com/mjbright/python-docker-machine
pythonsetup.pyinstall
Initializingthemodule:
importmachineimportdockerm=machine.Machine(path="/usr/local/bin/docker-machine")
Docker-machinefromPython-2
@mjbright
Usingthemodule:
m.create('test-machine',driver='virtualbox',blocking=True)m.ls()client=docker.DockerClient(**m.config(machine='test-machine'))m.rm(machine='test-machine')
Docker-machinefromPython-3
@mjbright
Thismodule,github.com/docker/docker-pyismaintainedbytheDockerteam.
NOTE:Nowcalled"docker",use"pipinstalldocker",notdocker-py.
Currentlyatthe2.4.2releaseithas2apis
docker-py:ControllingDockerfromPython
alow-level'docker.APIClient'api
withoperationscorrespondingtotheDockerapi
e.g."create_container","inspect_container",...
ahigher-level'docker.Client'object-orientedapi
objectssimilartonew(>1.13)"docker"clientcommands
e.g."docker.containers.create","docker.images.list"@mjbright
TherearemanydockerrelatedPythonmodules,"pip3searchdocker"gives443entriesofwhich217havedockerinthetitle,including:
OtherModules
buildtools
e.g.docker-build-tool,whalelinter,grocker
alternativeAPIclients
e.g.aiodockerpy,docker-map,python-dockercloud
Dockerbasedutilities
e.g.docker-cleaner,docker-scripts,dockeranalyser
Monitoringtools
e.g.check_docker,dockermon
CItools
e.g.travis2docker,@mjbright
ProvidesausefulabstractionforbuildingandrunningcontainersusingtheAnsibleConfigurationManagementtool.
Imagefrom:https://tech.napsty.com
AnsibleContainer
@mjbright
Install:-pipinstallansible-container
Initializeanewproject:generatesyamltemplatefiles
Modifyyamlfilesasneededforyourproject,thenbuild:
Run:
Whenreadyuploadcontainerimagestoyourconfiguredregistry:
AnsibleContainer
ansible-containerinit
ansible-container--debugbuild
ansible-containerrun
ansible-containershipit
@mjbright
Questions?
@mjbright
Resource Docs Github
RunningPythonunderDocker
Docker-py docker-py.readthedocs.io docker/docker-py
DockerMaps
AnsibleContainer ansible.com/anisble-container
ansible/ansible-container
Resources
@mjbright