docker and python - mjbright.github.io€¦ · what "standard" images exist on the docker...

14
Docker and Python @mjbright 3 juillet 2017, RMLL St-Etienne, Michael Bright

Upload: others

Post on 22-May-2020

20 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Docker and Python - mjbright.github.io€¦ · What "standard" images exist on the Docker Hub? hub.docker.com Running Python apps under Docker -2 Python : "python" small, large base

DockerandPython

@mjbright

3juillet2017,RMLLSt-Etienne,MichaelBright

Page 2: Docker and Python - mjbright.github.io€¦ · What "standard" images exist on the Docker Hub? hub.docker.com Running Python apps under Docker -2 Python : "python" small, large base

Agenda

RunningPythonappsunderDocker

TheDockerAPI

Docker-machinefromPython

docker-py:ControllingDockerfromPython

OtherModules

AnsibleContainer

@mjbright

Page 3: Docker and Python - mjbright.github.io€¦ · What "standard" images exist on the Docker Hub? hub.docker.com Running Python apps under Docker -2 Python : "python" small, large base

OfcoursewecanrunanyappunderDocker-Pythonornot.

Thiscanbeaveryusefulalternativetovirtualenv

RunningPythonappsunderDocker

completefilesystemisolationallowingtohavecomplexdependanciesbeyondPythonitself

launchmultipleinstancesofaPythonprocessinisolation

isolatedfilesystem,processspace,ports

pullexistingimagesofapplications,frameworks

builduponexistingimagesandpushtheresultstoshare

cancomposecomplexapplicationsfrommultiplecontainers

@mjbright

Page 4: Docker and Python - mjbright.github.io€¦ · What "standard" images exist on the Docker Hub? hub.docker.com Running Python apps under Docker -2 Python : "python" small, large base

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

Page 5: Docker and Python - mjbright.github.io€¦ · What "standard" images exist on the Docker Hub? hub.docker.com Running Python apps under Docker -2 Python : "python" small, large base

Let'stakealookathowthedockercommand-lineclientmakesuseofthedockerAPItoperformrequests

Canwemakeourowncommand-linerequestsusingcurl?

TheDockerAPI

@mjbright

Page 6: Docker and Python - mjbright.github.io€¦ · What "standard" images exist on the Docker Hub? hub.docker.com Running Python apps under Docker -2 Python : "python" small, large base

Therearemanydocker-relatedmodulesavailableinPython.

Let'sfirstlookat"docker-machine"whichprovidesasimple-*encapsulationaroundthedocker-machineexecutable.

*-abittoosimple:ifdocker-machineissuesapromptyouwillnotbeinformed(problemwithAzurelogin).

NeverthelessitprovidesanicewrapperenablingtosimplyfireupDockerhostsandpasstheirconfigtothedocker-pyclient.

Docker-machinefromPython

@mjbright

Page 7: Docker and Python - mjbright.github.io€¦ · What "standard" images exist on the Docker Hub? hub.docker.com Running Python apps under Docker -2 Python : "python" small, large base

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

Page 8: Docker and Python - mjbright.github.io€¦ · What "standard" images exist on the Docker Hub? hub.docker.com Running Python apps under Docker -2 Python : "python" small, large base

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

Page 9: Docker and Python - mjbright.github.io€¦ · What "standard" images exist on the Docker Hub? hub.docker.com Running Python apps under Docker -2 Python : "python" small, large base

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

Page 10: Docker and Python - mjbright.github.io€¦ · What "standard" images exist on the Docker Hub? hub.docker.com Running Python apps under Docker -2 Python : "python" small, large base

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

Page 11: Docker and Python - mjbright.github.io€¦ · What "standard" images exist on the Docker Hub? hub.docker.com Running Python apps under Docker -2 Python : "python" small, large base

ProvidesausefulabstractionforbuildingandrunningcontainersusingtheAnsibleConfigurationManagementtool.

Imagefrom:https://tech.napsty.com

AnsibleContainer

@mjbright

Page 12: Docker and Python - mjbright.github.io€¦ · What "standard" images exist on the Docker Hub? hub.docker.com Running Python apps under Docker -2 Python : "python" small, large base

Install:-pipinstallansible-container

Initializeanewproject:generatesyamltemplatefiles

Modifyyamlfilesasneededforyourproject,thenbuild:

Run:

Whenreadyuploadcontainerimagestoyourconfiguredregistry:

AnsibleContainer

ansible-containerinit

ansible-container--debugbuild

ansible-containerrun

ansible-containershipit

@mjbright

Page 13: Docker and Python - mjbright.github.io€¦ · What "standard" images exist on the Docker Hub? hub.docker.com Running Python apps under Docker -2 Python : "python" small, large base

Questions?

@mjbright

Page 14: Docker and Python - mjbright.github.io€¦ · What "standard" images exist on the Docker Hub? hub.docker.com Running Python apps under Docker -2 Python : "python" small, large base

Resource Docs Github

RunningPythonunderDocker

Docker-py docker-py.readthedocs.io docker/docker-py

DockerMaps

AnsibleContainer ansible.com/anisble-container

ansible/ansible-container

Resources

@mjbright