What does `docker build` do?

QuestionsQuestions8 SkillsProDec, 18 2025
0107

Great question!

In simple terms, docker build takes your Dockerfile (the "blueprint" you just created) and turns it into a Docker Image (the actual "package" or "template").

Here is a breakdown of what happens when you run sudo docker build -t ssh-server .:

  1. Read the Instructions: Docker reads the Dockerfile in your current directory (that's what the . at the end of the command stands for).
  2. Execute the Steps: It goes through the file line by line:
    • It starts with the base OS (FROM ubuntu:22.04).
    • It runs the commands to install software (RUN apt-get update...).
    • It sets up the user and configurations you defined.
  3. Create Layers: Each instruction creates a "layer" in the image. This makes it efficient because if you change one line later, Docker only has to rebuild that specific part.
  4. Tag the Result: The -t ssh-server part gives your finished image a name ("ssh-server"), making it easy to reference later.

Analogy:

  • Dockerfile: A recipe.
  • docker build: The act of cooking.
  • Docker Image: The finished cake (which you can then "serve" or run as a container).

Once the build is finished, the image is stored on your machine, ready to be launched as a running container!

0 Comments

no data
Be the first to share your comment!