If this helped you, please share!

Why do I use containers?

Published May 2, 2018 in devops - 0 Comments

Here are my best reasons for using container solutions like Docker:

1. Simplify the deployment process!

I used to struggle with software deployments. Traditional software package installers work fine for simple deployments on a single platform type, but require maintenance if deployment guidelines change between OS verisons. Deployment tools that need to target multiple platforms are much harder to maintain. Dealing with configurations and potential library conflicts adds to the fun. Even software implemented in interpreted languages frequently has platform-specific dependencies that need to be managed.

Using containers has significantly cut the amount of time and effort I spend managing deployments. I especially like containers for Python projects. Having pip or conda configure the right environment once in a container saves a lot of time and trouble.

2. No more dependency hell

Use containers to isolate software dependencies from the host the container is running on. For example, an app requires Python 3.6 but the host OS only supports older versions natively, or needs libraries that could conflict with system libraries.

3. Containers are portable!

The same image can be run reliably on a variety of hosts. Containers can still be challenging to use on Windows however.

4. Testing in CI/CD builds

Containers like Docker build their images in layers. Images with test suites and the tools needed to run in a CI/CD build environment can be built and cleaned up when no longer needed. For Docker, either the Builder pattern or multi-stage builds can be used. Multi-stage builds are currently recommended.

5. Leverage efficient deployment tools

Deployment tools like Kubernetes and SaltStack were built to support containers.

6. Restart

Containers can be restarted automatically. For example, Docker offers 4 restart policy options. Pick the one that makes the most sense for your deployment. Kubernetes pods also leverage container restart policies.

7. Limit and isolate resources

Containers like Docker can be run with limits on host resources. Filesystem access can be limited as well. Just remember to use good security practices like not using the root user.

8. Use tools with low commitment

Try out a new Python version or test a database. Recently, I needed to use the gdb debugger on a CI build agent to figure out why a tool in our data pipeline was dumping core, but didn’t want to pollute with packages I’ll only use rarely. Grabbing an image with gdb was easy and quick.

The overhead of running software in a container is usually small and manageable, unless there are very stringent performance requirements. Tricky use-cases like requiring hardware accelerated OpenGL drivers might also be a problem. Debugging crashed containers can also be challenging.

Getting software configurations and dependencies right shouldn’t be a time-consuming burden. For the projects I’ve been working on however, the benefits of using containers definitely outweigh the drawbacks.

Tags: docker, python

No comments yet

Leave a Reply: