Loading

Quipoin Menu

Learn • Practice • Grow

docker / Building Images
tutorial

Building Images

After writing a Dockerfile, the next step is to build an image from it. The docker build command reads the Dockerfile and creates an image.

The Build Command

Navigate to the folder containing your Dockerfile and run:
docker build -t my-python-app .
Here:
  • -t my-python-app gives the image a name and optionally a tag (e.g., my-python-app:v1).
  • The . at the end specifies the build context – the current directory.

What Happens During Build

Docker sends the build context (everything in the current folder) to the daemon. It then executes each instruction in the Dockerfile, layer by layer. If an instruction hasn't changed since the last build, Docker reuses the cached layer, making builds fast.

Tagging Images

You can assign multiple tags to the same image:
docker build -t my-python-app:latest -t my-python-app:v1 .

Viewing Built Images

After building, verify with:
docker images | grep my-python-app

Common Build Options

  • --no-cache: Ignore cache and rebuild all layers.
  • -f: Specify a Dockerfile with a different name or path: docker build -t myapp -f Dockerfile.prod .
  • --build-arg: Pass build‑time variables.

Testing Your Image

Run a container from the newly built image:
docker run my-python-app
You should see the output from your Python script.


Two Minute Drill
  • Build an image: docker build -t name . in the directory with Dockerfile.
  • The build context is the folder you specify (often .).
  • Docker caches layers for faster rebuilds.
  • Use tags to version your images.
  • Test with docker run name.

Need more clarification?

Drop us an email at career@quipoinfotech.com