Hello Whale: Images vs. Containers in Docker

Welcome! 👋 🐳

If you’re getting started with Docker, you’re probably hearing the word “container” or “image” quite a bit, but you’re probably wondering… what’s the difference? 🤔

To break things down simply…

An image is an application you would like to run.

A container is a running instance of an image.

In other words, you create a new container based on an image. Therefore, many containers can be run off the same image. So, a container is an instance of an image.

Wait, what? 😳

You can think about images and containers as a class and an instance of class. Here’s a simple example in Python:

class Whale(object):
order = “Cetacea”
suborder = “mysticeti”
    def __init__(self, name, location=”ocean”):
        self.name = name
self.location = location
    def speak(self):
return “EEEeooooOOOEOEOOooOOO, I’m {} the whale and I
live in the {}.”.format(self.name, self.location)
whale_1 = Whale(“Willy”)

In this example, the image would be our class Whale and whale_1 would be a container. Simple, no?

Alright, here’s a metaphor:

Wow- skills!

Imagine you have a copy of a film that (because you are a hipster) you decide to buy a VHS of. In this example, the VHS would be your image. When you play this VHS on your VCR, the VCR would be your container (in that we are running the original VHS in it). In this example, the container (in this case, the VCR) is always tied directly to the image.

And to stretch this metaphor even further:

Imagine you had a DVD and BluRay of a film. These would be your images, while their respective players would be containers.

And to stretch this metaphor even more further:

Imagine you had a LaserDisc… (ok, you get the point). Same content- different environments.

And there you have it- a super simple way to remember the difference between containers and images!

Wow- ok lady. It’s just a VCR. Calm down.

🐳 To hear more beginner-friendly articles about Docker, follow me on the Codefresh Blog, or find me on Twitter @chloecondon 🐳


Originally published at codefresh.io on May 5, 2017.

Chloe is a Developer Evangelist at Codefresh- a Docker native CI/CD known for it’s incredibly fast builds, unique image management capabilities, and pre-staging environments. Codefresh is free to use with unlimited repos, users, and builds. Start an account with Codefresh today and see how quickly you can be building, testing, and deploying today!