Learn Docker With My Newest Course

Dive into Docker takes you from "What is Docker?" to confidently applying Docker to your own projects. It's packed with best practices and examples. Start Learning Docker →

Docker Tip #5: The Benefits of Using the Same Base OS for All Images


Docker will happily build your images if they have a different OS, but you can get a few quick wins by using the same base OS all around.

Quick Jump: Save Disk Space | Easier to Maintain Your Dockerfiles

In the previous tip, I mentioned your Docker image does not need to match your Docker host’s OS, but now we’re talking about something much different.

Let’s say that your project is composed of 3 services:

  • PostgreSQL
  • Redis
  • A Flask web application

You would likely have 3 separate Docker images, and it would be a good idea to reach for the official PostgreSQL, Redis and Python (Flask is a Python web framework) Docker images.

Save Disk Space

If you pick the Alpine based official images for all 3, then a single copy of Alpine will be shared for all 3 Docker images as long as the Alpine version lines up. This is a very efficient way to use the disk space on your machine, and you can thank Docker’s layer caching mechanism for that.

It’s also worth mentioning that you could use a different base OS for each Docker image, but then you lose out on the ability to cache it across all of your images, however it will still work.

Easier to Maintain Your Dockerfiles

If you’re mixing and matching your base operating systems for each Docker image then you’re putting a pretty big cognitive load on your brain.

Now you need to keep track of package managers for different distributions of Linux. For example, Debian has apt but Alpine uses apk. Package names will also be different too.

If you stick to 1 base OS in your Docker images, then you always know what you’re working with. It doesn’t matter if it’s Alpine or not, just pick one.

What other benefits have you found?

Free Intro to Docker Email Course

Over 5 days you'll get 1 email per day that includes video and text from the premium Dive Into Docker course. By the end of the 5 days you'll have hands on experience using Docker to serve a website.