This story is inspired by at writing a Docker-esque container daemon in 100% Python. my futile attempt Trick 1: Docker for Python pip install docker Working with the Docker CLI is fine, but working with the API from Python is much better. You can list containers, look at the attributes and using the 3 other tricks, leverage them for power features. Trick 2: Namespaces for Python pip install nsenter Thanks to the folks at Zalando for this one, it’s a wrapper for the C API to enter a Kernel Namespace. With Docker, a docker running container has it’s own namespace. This is what protects it from the other containers on the host, keeps it isolated. in their great blog post. More details here Using nsenter is straightforward, let’s say you start a new nginx container using and you get back a container ID of 277906bc266c, you can get the running process ID with this command. docker run -d nginx Use the example in Trick 1 to get the process ID. Use that process ID to jump into the namespace and run a command, look at the file system or just generally wreak havoc. ? Well, you’ll often find yourself hopping up a bash session for a running container to debug a few bugs in your code (me? never!), well it’s called Bash for a reason, so why use a hammer when you can use a ? Why sonic screwdriver Trick 3: for Python cgroups pip install cgroups Control groups are the way that Docker, and other tools ensure that a particular process doesn’t get carried away and use up all the resources on that host. You can, using the package both create, list an manipulate existing cgroups on the host. CPU limits for example, aren’t set on a container by default, so you can use Python to dynamically shift resources around on the host. This example starts a new process and moves it to a cgroup, you can do a similar thing with the existing process that Docker has started. cgroups Thats all for now, check out my Docker Daemon implementation on GitHub if you want some solid examples of using these packages https://github.com/tonybaloney/mocker is how hackers start their afternoons. We’re a part of the family. We are now and happy to opportunities. Hacker Noon @AMI accepting submissions discuss advertising & sponsorship To learn more, , , or simply, read our about page like/message us on Facebook tweet/DM @HackerNoon. If you enjoyed this story, we recommend reading our and . Until next time, don’t take the realities of the world for granted! latest tech stories trending tech stories