Docker, start to ship · Chapter 6 of 26

The image warehouse

By the end of this chapter you can tell an image from its names, tidy up the images on a machine, count an image's layers, and carry an image to another machine as one file. Build it in your browser: a real editor and terminal, AI that explains, and tests that tell you when it works.

  • Part: Images and Dockerfiles
  • 4 tasks
  • Docker
  • In the all labs plan

The first 2 chapters of Docker, start to ship are free. This one comes with the all labs plan.

Why you need this

Bunty built the menu site into an image and was so sure it was the last one that he tagged it three times:

$ docker images chai-06-menu
REPOSITORY              TAG          IMAGE ID      CREATED        SIZE
localhost/chai-06-menu  final        e3cdab59231a  4 seconds ago  49.7 MB
localhost/chai-06-menu  final-final  e3cdab59231a  4 seconds ago  49.7 MB
localhost/chai-06-menu  latest       e3cdab59231a  4 seconds ago  49.7 MB

Ravi needs a proper version number on it, a warehouse with nothing old lying around, and the image on the new branch's server, which has no registry and no internet. With what you know so far you can only run images. Building it again on that server would give a different image, and nobody could say which one was tested.

What you build: 4 tasks

Each task has tests. You write the code in the lab's editor and press Check.

  1. Task 1

    Tag Bunty's menu image as chai-06-menu:1.0

    Bunty's menu image has three names: chai-06-menu:final, chai-06-menu:final-final and chai-06-menu:latest. Give it a good name.

    1. Run docker images. All three names have the same image ID.

    2. Give the image the new name chai-06-menu:1.0 with docker tag. Do not build a new image.

    3. Run docker images chai-06-menu. You see four names and one ID.

    To pass: chai-06-menu:1.0 is the same image as Bunty's, with the same image ID.

  2. Task 2

    Delete the old tags and the junk image

    Delete the names you do not need.

    1. Delete the names chai-06-menu:final, chai-06-menu:final-final and chai-06-menu:latest with docker rmi. Delete them by name, not by ID.

    2. Delete the image chai-06-junk:old too.

    3. Delete any practice names you made that start with chai-06.

    To pass: the only image name left that starts with chai-06 is chai-06-menu:1.0.

  3. Task 3

    Count the layers of chai-06-menu:1.0

    Count the filesystem layers in chai-06-menu:1.0.

    1. Run docker image inspect on chai-06-menu:1.0. Find RootFS and its Layers list.

    2. Count the layers in that list. Do not count the rows of docker image history.

    3. Save only the number in layers.txt, in the chapter folder.

    To pass: layers.txt has the number of layers in RootFS.Layers of chai-06-menu:1.0, and no other number.

  4. Task 4

    Save it to chai-06-menu.tar and load it back

    Save the image in a file, delete it, then load it back from the file. Do the steps in this order.

    1. Save chai-06-menu:1.0 with docker save into the file chai-06-menu.tar, in the chapter folder. Use the name chai-06-menu:1.0, not the ID.

    2. Delete chai-06-menu:1.0 with docker rmi chai-06-menu:1.0.

    3. Load it back from chai-06-menu.tar with docker load.

    4. Run docker images chai-06-menu. 1.0 is back, with the same ID.

    To pass: chai-06-menu.tar is in the chapter folder and has the name chai-06-menu:1.0 in it. You ran docker rmi chai-06-menu:1.0, and after it docker load, both in the chapter folder, and both worked. chai-06-menu:1.0 is back, with the same image ID.

What you will learn

  • Tags and IDs: an image is its ID; a tag is only a name pointing at it, and docker tag adds one.
  • docker rmi: removes a name, and the image goes with its last name.
  • Layers: what docker image history lists, and how many layers an image really has.
  • docker save and docker load: an image packed into one tar file, and unpacked again.

More in Images and Dockerfiles

Build The image warehouse yourself

Tapri’s menu site works on one laptop and nowhere else. You ship the machine. A real editor and terminal in your browser, AI that explains, and a Check that says when it works.

The first 2 chapters of Docker, start to ship are free. This one comes with the all labs plan.