Member-only story
Docker for absolute beginners: the difference between an image and a container
Learn the difference between Docker images and containers + practical code examples
Containers, images, environments, building, running, virtual machines.. when you’re new to Docker all of these abstract terms can be a bit confusing. In this article we’ll go through all of them and get an understanding of each term. We’ll focus on explaining the difference between images and containers and how they work together, but along the way we’ll explore other Docker-related things. At the end of this article you’ll:
- understand how to build an image
- understand how to spin up an image
- understand the difference between an image and a container
- understand how to user Docker better in your day-to-day work
Let’s code!
Docker in a nutshell
Docker is the answer to ‘but it worked on my machine!’ Imagine that you’ve written a small program on your laptop: let’s say that it’s a simple Python API. Now you want to deploy this program on a laptop of a coworker or on a server. You copy the code, spin up the API and it crashes. Why?
There reasons for this can be many: maybe Python isn’t installed. Maybe the other machine has an OS that’s incompatible with your code. In other words: your program is built in one environment and doesn’t work in another.
Docker’s solution to this problem is very simple and very clever at the same time: instead of just deploying the code, we’ll deploy our environment as well. Docker creates a box, installs an OS in the box and copies over your source code. Then we give others the box. This is brilliant because once your code runs in this environment (box) that means that it runs anywhere.
In this article we’ll focus on how we build these boxes and how to share them. In other words: how we build images, spin them up into containers and deploy them on a server for example!