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

Previous episode Works on my machine: why your app breaks on the server

What happens when you put your app in a Docker container

Dockerfile and docker build: how your app becomes an image

Docker can pack an app in one image, with Python and every library the app needs. But Docker cannot guess which version of Python you want. It cannot guess which file starts your app either.

  1. 1 So you tell Docker, step by step, in a small text file next to your app. You write this list only once, and the file is called a Dockerfile.youDockerfile1. start from Python2. add dependencies3. copy your app4. say what to start

    So you tell Docker, step by step, in a small text file next to your app. You write this list only once, and the file is called a Dockerfile.

  2. 2 Now one command, docker build, puts Docker to work. It opens your Dockerfile and follows the steps in order, from top to bottom.Dockerfile1. start from Python2. add dependencies3. copy your app4. say what to startDockerreadsStartingstep 1.

    Now one command, docker build, puts Docker to work. It opens your Dockerfile and follows the steps in order, from top to bottom.

  3. 3 The first step holds a nice surprise: Docker installs nothing. It downloads an image that someone already made with Python inside, and builds yours on top of it. That starting image is called a base image.DockerPython?Someone alreadypacked it.from the internetbase imagePython

    The first step holds a nice surprise: Docker installs nothing. It downloads an image that someone already made with Python inside, and builds yours on top of it. That starting image is called a base image.

  4. 4 From there, the rest goes fast. Docker adds the dependencies, copies your app in and notes what to start.DockerDone!buildsimageyour appdependenciesPythonfrom thebase image

    From there, the rest goes fast. Docker adds the dependencies, copies your app in and notes what to start.

  5. 5 Your image is ready, with everything inside. But it sits on your laptop, and the server, where Miva's requests will go, has never seen it.your laptopimage?the server

    Your image is ready, with everything inside. But it sits on your laptop, and the server, where Miva's requests will go, has never seen it.

  6. Quick check

    Your laptop is almost out of space.You uninstallPython fromyour laptop. Doesdocker buildstill work?

    Your laptop is almost out of space.

    Show the answer

    Yes. Python comes from the base image, and the dependencies are downloaded during the build. From your laptop, Docker takes only your app and the Dockerfile.

  7. Go further

    Two more words from the build.3. copy your appinstructionone step of a Dockerfile.It starts with a shortword in capitalsdependenciespackage managerthe program thatdownloads thedependencies

    Two more words from the build.

Next episode Docker registry: how your image gets to the server

Share this comic

More comics