What Is a Container?
Throughout this course you will package one small web app, quicknotes: a Python program that serves a notes page on port 5000. On your laptop it runs fine. The moment you want it to run the same way on a friend's laptop, a test server and a cloud machine, you need a container. So first, what is one?
The rule
A container is an ordinary process with a private view and a budget.
Take the rule apart:
- Ordinary process. When quicknotes runs in a container, it is still just a
pythonprocess on the host's own kernel. There is no second operating system underneath it. - Private view. The kernel shows that process its own filesystem, its own process list, its own network and hostname. From inside, it looks like it has a small machine to itself.
- A budget. The kernel can also cap how much CPU and memory the process may use.
The files it sees come from an image: a read-only package holding the app's code, the Python runtime, the libraries and a note about which command to start. The container is one running instance made from that image.
docker run -d -p 8080:5000 quicknotes:1.0That single line asks Docker to take the quicknotes:1.0 image and start a container from it. If you then list processes on the host, you will find the python process sitting there like any other program.