Docker, start to ship · Chapter 3 of 26

Break in and look around

By the end of this chapter you can work inside a running container: run commands in it, copy files in and out, and read its settings. Build it in your browser: a real editor and terminal, AI that explains, and tests that tell you when it works.

  • Part: Containers
  • 5 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

The orders API runs in chai-03-api. Bunty spent an evening "debugging it from the inside", and on the way he saved Tapri's payment key in a hidden file somewhere under /app, so he would not have to type it again. Kabir wants it out of there, kept safe, and deleted inside. Meera has a new menu (menu.json in the chapter folder) that the API must serve today. And Ravi wants to know where on the lab machine the API keeps its orders, so he can back them up.

So far you can only start and stop containers from the outside. Removing chai-03-api and starting a fresh one would lose what is inside it and stop the orders. You need to get in while it runs.

What you build: 5 tasks

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

  1. Task 1

    Run a command inside chai-03-api

    Run a second command inside a container that is already running.

    1. Run docker exec, then the name chai-03-api, then a command to run inside it.

    2. A listing of the /app folder is a good command to try.

    To pass: you ran docker exec chai-03-api with a command after the name, in the chapter folder, and it worked. A command with a typing mistake or an error does not count, so type it again.

  2. Task 2

    Copy Bunty's key out as bunty.key

    Bunty saved a payment key in a hidden file somewhere under /app in chai-03-api. Copy it out.

    1. Find the hidden file under /app inside chai-03-api. Hidden names start with a dot.

    2. Copy the file out of the container with docker cp, into the chapter folder, with the name bunty.key.

    3. Run cat bunty.key to see the key.

    To pass: bunty.key in the chapter folder has exactly the key from the container, and you ran docker cp from chai-03-api in the chapter folder. Copy it before you delete it in task 3.

  3. Task 3

    Delete the key inside chai-03-api

    Delete Bunty's key file inside the container.

    1. Do task 2 first. The key must be copied out before you delete it.

    2. Use docker exec to run rm inside chai-03-api, with the full path of the hidden file.

    3. Do not delete the container, and do not start a new one.

    To pass: the key file is gone from chai-03-api, chai-03-api is still running, and the app is still inside it.

  4. Task 4

    Copy Meera's menu into chai-03-api

    Meera wrote a new menu. Put it into the running app.

    1. Copy menu.json from the chapter folder into chai-03-api at /app/menu.json with docker cp. It replaces the old one.

    2. Run curl localhost:8003/menu to see the new menu.

    To pass: localhost:8003/menu shows the new menu, with Bun maska in it.

  5. Task 5

    Save the orders folder in orders-path.txt

    chai-03-api sees a folder of the lab machine as /data. Find which folder it is.

    1. Run docker inspect chai-03-api and look at Mounts.

    2. Find the mount whose Destination is /data. Its Source is the folder on the lab machine.

    3. Save only that Source path in orders-path.txt, in the chapter folder.

    To pass: orders-path.txt has the full Source path of the /data mount, and nothing else.

What you will learn

  • docker exec: runs another command inside a running container.
  • docker cp: copies files from a container to the lab machine, and back.
  • docker inspect: everything Docker knows about a container, with -f to pick one field.

More in Containers

Build "Break in and look around" 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.