Writing Your First Spell Scroll
Concept:
A Dockerfile is a text file with instructions to build a Docker image. Key instructions: FROM (base image to start from), RUN (execute commands during build), CMD (default command when container starts). Every Dockerfile must start with FROM. Real-world use: package your Java app so anyone can run it identically — no JDK installation needed on the target machine.
Old Wizard Dockerus:
You've summoned creatures from existing blueprints. Now it's time to write your OWN spell scroll — a Dockerfile!
Apprentice:
My own spell scroll! What goes into it?
Old Wizard Dockerus:
Every scroll begins with FROM — the foundation spell. It declares which existing creature you're building upon. 'FROM eclipse-temurin:21' means 'start with a creature that already has Java 21 installed.'
Apprentice:
So we stand on the shoulders of existing creatures?
Old Wizard Dockerus:
Exactly! Then comes RUN — the transformation spell. 'RUN javac -version' verifies your creature's powers during creation. You can have many RUN spells — installing libraries, compiling code, anything!
Apprentice:
And when the creature is summoned, what does it do?
Old Wizard Dockerus:
That's CMD — the purpose spell. It tells the creature what to do when it awakens. 'CMD ["java", "App"]' means 'when summoned, run the Java application.' Every creature needs a purpose!
Apprentice:
FROM for foundation, RUN for teaching, CMD for purpose. Let me try!
Old Wizard Dockerus:
Write your scroll in the console below. Three lines: the foundation, the teaching, and the purpose.
Example Code:
FROM eclipse-temurin:21
RUN javac -version
CMD ["java", "App"]
Your Assignment
Write a Dockerfile that starts FROM eclipse-temurin:21, RUNs 'javac -version' to verify the compiler, and sets CMD to run 'java App'. Write each instruction on a new line.
Docker Console