Lesson 04/7 minutes/2 graded
Images and containers
An image is the package and a container is that package running. The two words people mix up all the time, sorted out for good.
These two words come up in every Docker sentence you will read, and people mix them up constantly. They are simple once you see where the line sits.
An image is a package
You have shipped a build artifact before. A jar file, a zip, a folder of compiled files. You upload it somewhere and download it on the server when you need it.
A Docker image is that same idea with more inside it. Along with your compiled code, the image holds the environment your code needs. A small Linux application layer. The tools your app runs on, so node and npm for a JavaScript app, or a Java runtime for a Java app. Environment variables. Any folders or files you want created before the app starts.
All of it sits in one package that you can share, and that is the piece teams pass around instead of a document full of setup steps.
A container is that package running
An image on its own does nothing. It sits on disk. Run it and the app inside starts in the environment that was packaged with it, and that running thing is a container.
So a container is a running instance of an image. Nothing more mysterious than that.
One image can give you as many containers as you want. Start the same image three times and you get three containers, all with the same code inside, running independently. That is how you would run three copies of an app when one is not keeping up.
Seeing both on your machine
Docker keeps a list of each. Images you have downloaded or built live in one list, and containers live in another.
If you followed the install lesson, the hello-world image shows up here, along
with its size. Run docker ps again and you will still see no containers,
because the one from hello-world printed its message and exited.
That last part is worth holding on to. A container stops when the program inside it finishes. It does not disappear when it stops, though, and that catches people out later.