Taming Snakes inside a Container

apcelent

Apcelent

Posted on August 6, 2018

Taming Snakes inside a Container

In this post, let's talk about taming snakes inside a container. The article is a summary of lessons learned while dockerizing python microservices. In case you want to see a detailed implementation of microservices with Docker and Python, kindly refer to this article which we have published.

Alt text of image

The prime reasons that we go with the container is that

  • containers have lower memory footprints than VMs
  • Containers provide an isolated user-space instance, instead of a machine emulation

It is easy to spin up new containers and set up environments. The images thus created can be shared and published to private/public registries, and are ready to be used. This provides with a unified workflow whenever a new developer starts working on the codebase.

Building python images with a container

  • We need not create an extra layer of the virtual environment since each container is unique in itself there is no additional need to create a virtual environment. Different Microservices can be put inside different containers.
  • An external proxy like NGINX can be used or altogether a separate container for NGINX can be deployed.

Debugging Python Containers

  • It is easy to run bash (or any other command ) on a running service


docker compose exec $SERVICE_NAME /bin/bash

  • Log inspection of standard output and error


docker compose logs $SERVICENAME

  • Low-level information can be got through


docker inspect $SERVICENAME

Persistence

Changes are lost once a running container shuts down. To overcome the same the strategies deployed are

  • Data Volume to an external host
  • Another pattern is using separate Docker container to save the data

Testing & Tooling

  • Docker adds consistency in your CI environments.
  • Control over what is in container implies repeatable workflow and simpler test environment.
  • Cloud-based CI options with docker support out there.
  • Docker Hub, can act as a CI server since you can configure it to create an automated build every time you push a new commit to Github.
  • Internal API can vary radically for Docker from version to version hence the usage of available tools is recommended.
  • Another Pythonic way of playing with Docker API is to use docker-py.

Deployment & Scaling

Hope the summary and links were of help! Do let us know in comments what other stuff would you like us to write about.

The article originally appeared on Apcelent Tech Blog.

💖 💪 🙅 🚩
apcelent
Apcelent

Posted on August 6, 2018

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related