What happens when you put your app in a Docker container
Works on my machine: why your app breaks on the server
Every developer has said it once: "but it works on my machine". An app runs fine on a laptop. You copy it to a server, and it crashes. Not one line of its code changed. The problem is everything around the code.
-
1
You wrote a small web app for Rono, a radio DJ. Tonight, during his show, his listeners will send him song requests with it.
-
2
Miva is one of those listeners, and her requests will come from her phone. Your laptop is not always on, so your app will live on a server, a computer that stays on day and night, ready for visitors.
-
3
Easy, you think: you copy your app's folder to the server and start it, just as on your laptop. It crashes at once.
-
4
Here is the trouble. The folder held only your app, and your app also needs Python and the packages of code it uses, called its dependencies. Your laptop has them all, but the server has an older Python and none of the dependencies.
-
5
Docker makes a promise for exactly this trouble: it packs your app, Python and the dependencies together in one image. With all of that inside, the server no longer needs its own Python or your dependencies.
-
Quick check
The show starts soon, and you look for a quick fix.
Show the answer
Maybe not. The server still has an older Python than the one you tested with, and a small difference in the dependencies can break an app.
-
Go further
Tonight's crash, with the real names.