We're sorry but this page doesn't work properly without JavaScript enabled. Please enable it to continue.
Feedback

Docker meets Python - A look on the Docker SDK for Python

00:00

Formal Metadata

Title
Docker meets Python - A look on the Docker SDK for Python
Subtitle
"pip install docker"
Title of Series
Number of Parts
118
Author
License
CC Attribution - NonCommercial - ShareAlike 3.0 Unported:
You are free to use, adapt and copy, distribute and transmit the work or content in adapted or unchanged form for any legal and non-commercial purpose as long as the work is attributed to the author in the manner specified by the author or licensor and the work or content is shared also in adapted form only under the conditions of this
Identifiers
Publisher
Release Date
Language

Content Metadata

Subject Area
Genre
Abstract
My talk aims to introduce and have a closer look on the Docker SDK for Python. I will cover: - How and where to get the SDK - How it works and how to use it in general - Possible use-cases like: Processing Container-Logs, Testing with pytest on different Python Versions, Deploy via Python Script, etc.. For my talk, you should know what Docker is and how to use it. A basic idea of pytest and server administration is nice to have, but not necessarily needed to follow my talk.
Keywords
20
58
Software development kitGoogolPoint cloudAuditory masking
Software development kitPersonal digital assistantScripting languageRevision controlCodeProcess (computing)BlogInformation technology consultingFocus (optics)Physical systemDefault (computer science)Configuration spaceCommon Language InfrastructureKinematicsExtension (kinesiology)Client (computing)Computer-generated imageryInterior (topology)Open setWritingTask (computing)Axiom of choiceReading (process)Type theoryStructural loadSoftware development kitStatement (computer science)Control flowWebsiteMultiplication signInformation technology consultingInformationMedical imagingProper mapException handlingEquivalence relationPoint (geometry)Physical systemService (economics)Computer fileDemonCASE <Informatik>Slide ruleLocal ringKey (cryptography)Uniform resource locatorDifferent (Kate Ryan album)Client (computing)Visualization (computer graphics)Electronic mailing listString (computer science)Variable (mathematics)Letterpress printingInstallation artLoginGraphical user interfaceComputer configurationObject (grammar)Web 2.0Extension (kinesiology)Lattice (order)Regular graphCodeParameter (computer programming)Task (computing)Revision controlStreaming mediaMoment (mathematics)Scripting languageAxiom of choiceDatabaseFlow separationProcess (computing)Line (geometry)Coefficient of determinationFile formatLogistic distributionProjective planeTouch typingOpen setKeyboard shortcutWeb pageHypermediaEmailLaptopData managementFitness functionText editorBlogComputer animation
Software as a serviceService (economics)Remote procedure callLocal ringComputer configurationParameter (computer programming)State of matterClient (computing)Multiplication signObject (grammar)Lecture/Conference
Point (geometry)Parallel portDemonCuboidService (economics)WindowVirtualizationMusical ensembleSoftwareLaptopSemiconductor memoryLecture/Conference
Transcript: English(auto-generated)
Hi. Yeah, thank you. I'm surprised, happy, and scared that so many people are here actually. So this is my second conference talk. So in case I collapse and faint, please don't make pictures, okay? Be cool. So welcome to my talk, Dogger Meets Python, a look on the Dogger SDK for Python.
And what I'm going to talk about is briefly introduce myself, then the Dogger daemon and the service, what that is, then of course the Dogger SDK, so that's the topic, right? So where you can get it, and some ideas of possible use cases.
So hi, my name is Jan, 32 years old, not married but engaged, no kids yet, so that's good for me at the moment. I'm a data science consultant at AxanTec, that's a small consultant company in Germany with different locations all around Germany.
And of course, like every company here, we focus on data. So if you're interested in job-wise or project-wise, just get in touch with me. You can do that via email, social media, or GitHub. I will put the slides on GitHub later, but they are already on the conference page,
so if you want to look them up. All right, Dogger. Who of you has used Dogger? Okay, that's good. So you basically know what it is and how it works. So after you installed Dogger on your systems, on your local laptop, I'm assuming just a local laptop, the daemon or the service is reachable per default from within the
system, so from local host, or you can configure it to be reachable from outside. And if you have the daemon, of course, you want to talk to it, kind of, and there are different ways to do that. So I separated the command line, you know, just put in Dogger something, something, or
you can use graphical user interfaces like Kitematic or the Dogger extension for Visual Studio Code, which I personally like a lot, or you can use web GUIs like Portainer. But, well, sometimes, depending what you want to do, these options are too big or too
small and maybe not customizable enough for you. So this is where the Dogger SDK comes into place. So just build your own.
To get it, it's easy, it's officially available for Python and Golang. There's an awesome documentation available, so it's really just pip, pip3 install Dogger. And for Conda, there's also a package available.
Some small code examples. If you go to the website, the code examples are written in Python 2. I don't know why it is supported, but I wrote them too. You see it on the print statement in Python 3. So on the left side, you see what you would usually type into the command line, and on the right side, you will see the equivalent if you would use a Python script and use
the Dogger SDK. So it's really just import Dogger. Then you get, you use some name like client, that would be best practice. Dogger.fromenv without any further parameters. This means you want to connect to your local Dogger service.
You can also connect to a remote one. And then you can pretty much do whatever you want. In this example, the print statement is only because hello world usually gets to you. Who did the hello world example from Dogger? Only a few. Okay, if you start this, this is just an image starting up a container, printing
on subtext, stopping the container, and that's it. So if you use the print statement here, you will see what was given out on the standard load. You can put an image, in this example, the Alpine image. It's pretty straightforward.
Nevertheless, a hint, if you're used to use the command line interface from Dogger, you usually type Dogger image, Dogger container. Dogger images is an exception that works on a command line. But if you use the SDK, it's always images and containers, so plural.
And if you use a proper IDE, autocomplete will solve this problem. But if you just go into, I don't know, some easy text editor, this might be a trap.
All right, so when I wrote the proposal, I was thinking about some ideas and use cases and some that I use. And one is, yeah, just to use Python as a container starting script. These are two examples, more or less, like the original on the Dogger hub site for Postgres.
And depending what you want to start, these commands get really, really long and complex. And if you want to change something in the middle, you have to use your back keys and you might save them in the text file and copy paste them to your command line.
But that's somehow not so cool. So my first idea was, OK, Python comes batteries included, just import OS. And then with os.system, you can give a command directly to your system shell. But I want to show you the Dogger SDK.
So this is maybe one example how it could work with the SDK. So you just declare your variables with strings or with a list of strings. And you get, again, the client object, the Dogger object in the variable client.
And then you can just put in to the parameters all your variables. And that way, you can easily list up all your parameters, more easy, more better to read, maybe easier to change if you have to change them regularly.
And I think sometimes this is quite useful. You could also extend it a little bit. So if a container is running at the moment, you could go and get that container and stop it.
You can prune it or delete it in that case if you haven't started with the command that it should delete automatically after you stopped it. Then, of course, you can build a new image from a Dogger file that is saved somewhere.
And you can get the idea and then start again a new container with a new image that you just built. Another idea was to get the logs. You can just stream the logs of one container and write your logs wherever you need them, maybe in a separate text file,
maybe directly into some database that you set up, or whatever comes to your mind and whatever is helpful for you. Of course, you can do this with several containers and not just with one. Then another idea that I had when I wrote the proposal was,
okay, why not save all your Python files in one folder, use it as mounting point, then spin up different containers with different Python versions and mount your Python files there and then run pytest.
And I have to admit that when I started to prepare the talk and then started to work out on this use case, somewhere in the middle I was like, okay, it can work, but maybe it's not really useful. So in that sense, maybe just, yeah, write a whole CI CD pipeline.
If you're at that point, maybe that's really the better choice. And yeah, I'm noticing I'm way too fast, like really way too fast. It means this is already a wrap-up. But I guess you're not so angry about it to get to the coffee break.
So yeah, depending on your task at hand that you want to serve on your laptop, Python might be a better choice than, for example, a best script, especially if you want to maintain it and maybe keep it readable, kind of.
And the Dogger SDK might sometimes be a better choice than import OS or equivalents. And yeah, at this point I hope that you at least have a high-level idea about the Dogger SDK and some inspiration there for your day-to-day work. And as a last hint, I can really recommend the Dogger documentation.
So for the SDK or for Dogger itself, it is usually up to date and really good and a lot of information. So now that I was so fast, we have a lot of time for questions.
Thank you. Thank you very much for the fast talk. And as you said, we have now a lot of time for questions.
So I will jump over this question. So first, a comment. I have been doing talks for like 13 years. And yesterday, I was also early by 10 minutes. So yes, that is not a problem. So you created a client by calling docker.fromenv.
What does it do exactly? And what are the other options for creating clients? So what it does exactly, exactly, I can't answer. But what it does, it basically creates an object that is connected to your local daemon,
to your local service, Dogger service. And of course, you can give it parameters to connect to some remote Dogger service. You can use it with authentication, with HTTPS, and so on and so forth. OK, thank you.
Can you go to the microphone? Hi, thank you. How is your experience with Windows, with this SDK? OK. But is there any issue?
Yeah, so if you install Dogger on your Windows laptop, it works. If you don't have like virtual box installed, that does not work in parallel. You have to activate and deactivate, what is it called, Hyper-V. So that's one point.
Another point is if you install Dogger on a Windows laptop, you have to give the service explicit resources, like memory, CPUs, and so on and so on. So it doesn't take that on need. And on the other side, all these resources are locked if you have the daemon running without any usage.
So it works. But on a Linux system, it works better. So at the end, it's just working with a common line? Yeah. OK, thank you. Any further questions? Cool, then. OK, then thank you very much again.
And have a good day. Thank you. Thank you.