Better Programming

Advice for programmers.

Follow publication

Member-only story

Container Images Are Like Cakes

Sunny Beatteay
Better Programming
Published in
5 min readJan 31, 2023
Photo by Bhuwan Bansal on Unsplash

Containers are a modern marvel.

They allow me to write, compile, and run code on a server without any of the dependencies installed.

I can run a Ruby on Rails application, or compile Rust code without having to download anything from Homebrew or apt-get. All I need to do is run them in a container.

The reason this is possible is because of container images.

Container images are static files that include everything a container needs to run — the system libraries, utilities, configuration settings, and the workload.

The image shares the operating system kernel of the host, so it does not need to include a full operating system (unlike a Virtual Machine).

Essentially, a container image is an entire filesystem that contains both the application code as well as all of its dependencies.

This is what makes containers portable.

So how do Docker and other runtimes build and create images? In short, it’s like layering a cake. But there’s a lot more to it than that.

The Dockerfile Recipe

To better understand docker images, we need to understand Dockerfiles. Let’s look at an example Dockerfile for a simple Golang application.

The first line of the Dockerfile — FROM golang:latest — is the base image of our container.

This base image contains all the libraries and dependencies needed for building, compiling, and running Go code.

This base image creates the foundational layer of our cake. However, most cakes have multiple layers, and so do container images.

You can think about the Dockerfile as a recipe for the container image.

Each line of the Dockerfile creates a new layer in the image. Each of these layers is a filesystem delta that adds to the…

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

Responses (1)

Write a response