How to Make Docker Containers Faster and Improve Performance

Your Docker containers are already fast, at least compared to virtual machines. But what if you want to make them even faster? Here are strategies for optimizing Docker container speed and performance.

If you’re using Docker, it’s probably at least partly because you want your applications to start and run faster. Out of the box, containers offer significant performance advantages over infrastructure built using virtual machines.

Making Containers Even Faster

But why settle for the speed containers give you out of the box? In many cases, there are things you can do to make Docker even faster. They include:

  • Make your container images lean and mean. When building a container image, include inside the image only what your application needs, and nothing more. For example, if you don’t need an SSH server inside your container, don’t include one. Minimizing the number of components and code inside container images not only helps to keep containers more secure, it also improves performance because resources are not wasted running unnecessary services.
  • Host Docker on bare metal. Containers that run directly on a bare-metal server, rather than inside a virtual machine, will generally perform better because no system resources are wasted on emulation. To optimize Docker performance, install Docker directly on a bare-metal server—or consider using a system container hypervisor, such as LXD or OpenVZ, and running Docker inside that. System containers give you an abstraction layer between the guest environment and the host without compromising bare-metal performance.
  • Use a minimalist host operating system. The more services you have running in the operating system that hosts your Docker environment, the fewer system resources are available for running your containerized apps. Using a bare-bones Linux distribution (such as Alpine Linux or RancherOS) for hosting Docker rather than a full-feature system will deliver better performance. Just make sure, of course, that your host system includes the security protections and other necessary features that you need to run Docker.
  • Use microservices. There are several advantages to migrating your app to microservices. Speed is one of them. Containers that host just a microservice rather than an entire monolithic app will start faster because they have less code to run.
  • Use a build cache. A build cache can speed the process of building Docker images—albeit with some important caveats that you should understand before using the build cache option.

Christopher Tozzi

Christopher Tozzi has covered technology and business news for nearly a decade, specializing in open source, containers, big data, networking and security. He is currently Senior Editor and DevOps Analyst with Fixate.io and Sweetcode.io.

Christopher Tozzi has 254 posts and counting. See all posts by Christopher Tozzi