You are signed in. Close

You are signed out. Close

Thank you. Your subscription has started. Close

Thank you. You will get an email when a new comic comes out. Close

We could not confirm your payment. If you paid, use the link "Sign in" at the bottom of the page. Close

Something went wrong on our side. Please try again in a moment. Close

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. 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.RonoOnline beforetonight's show?youyour app

    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. 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.MivaOne moresong, please!a server

    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. 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.your laptopyour appthe serveryour appSomethingis missing!

    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. 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.your laptopthe serverdependenciesPythonmissingolder Python

    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. 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.Dockerpacksimageyour appdependenciesPython

    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.

  6. Quick check

    The show starts soon, and you look for a quick fix.You install thedependencies on theserver by hand.Will it run now?

    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.

  7. Go further

    Tonight's crash, with the real names.dependencieslibrarya package of codethat many appscan usePythoninterpreterthe program thatruns Python codeimagecontainer imagethe full nameof an imageenvironmentall a computer hasaround your app

    Tonight's crash, with the real names.

Next episode Dockerfile and docker build: how your app becomes an image

Share this comic

More comics