Paths/DevOps Engineer/Docker / Building Images
Build Your Own Image
Instead of consuming images, make one. Write a Dockerfile, build it with a tag and run a container from your own image.
Validator
IDLE — checks run live as you type commands; submit when done
01Requirements
live checks- Directory ~/build exists with a Dockerfile○
- Image myapp:1.0 exists locally○
- A container from myapp:1.0 is running○
02Walkthrough
8 steps- 01
Create a build directory
docker build sends a directory (the build context) to the daemon. Keeping builds in their own folder keeps contexts small.
mkdir ~/build - 02
Write a Dockerfile
FROM scratch starts from nothing; COPY adds a file into the image; CMD is what runs when a container starts. One echo per line builds the file up.
echo 'FROM scratch' > ~/build/Dockerfile - 03
Add the copy instruction
This appends the COPY line to the Dockerfile with >>.
echo 'COPY app /app' >> ~/build/Dockerfile - 04
Add the start command
The final line. cat the Dockerfile to see all three instructions.
echo 'CMD ["/app"]' >> ~/build/Dockerfile - 05
Enter the build directory
docker build is always run from the directory containing the Dockerfile — the build context.
cd ~/build - 06
Build the image
docker build reads the Dockerfile and produces an image. -t myapp:1.0 tags it with a name and version. The . means 'use the current directory as context'. Then verify with docker images.
docker build -t myapp:1.0 . - 07
Run a container from your image
Now your image is first-class: run it detached with a port mapping, exactly like the official one.
docker run -d -p 8081:80 myapp:1.0 - 08
Submit for validation
The validator checks the Dockerfile exists and a container from myapp:1.0 is running.
03Stuck?
0 of 3 revealedTake a hint without losing the lab — each one points at the thing to look at, not at the answer.
04AI Tutor
guides, never solvesTell me what you're stuck on — I'll nudge, not solve. Which requirement are you looking at?
04Notebook
saved locally in this browserlearner@lab — docker:24
Session is disposable
↑/↓ recalls commands · Ctrl+Enter submits · type help for the command list