Table of contents:

  1. What is Dockerfilet
  2. Example
  3. Building docker image
  4. Dockerfile build image output
  5. Context

What is Dockerfile

In short:

  • a Dockerfile is a text document that contains all instructions users provide to assemble an image
  • each instruction will create a new image layer to the image
  • instructiuons specify what to do when building the image


FROM debian:jessie
RUN apt-get update
RUN apt-get install -y git
RUN apt-get intall -y vim

Building docker image

To build docker image run:

docker build -t debian . --no-cache=true

Dockerfile build image output

Sending build context to Docker daemon  3.072kB
Step 1/4 : FROM debian:jessie
 ---> 3aaeab7a4777
Step 2/4 : RUN apt-get update
 ---> Using cache
 ---> 02fc61b53c55
Step 3/4 : RUN apt-get install -y git
 ---> Using cache
 ---> bc4def3544ba
Step 4/4 : RUN apt-get install -y vim
 ---> Using cache
 ---> 352d7320c16b
Successfully built 352d7320c16b
Successfully tagged debian:latest

Of course there is build output from cache. Docker image:

REPOSITORY   TAG           IMAGE ID       CREATED         SIZE
debian       latest        352d7320c16b   3 minutes ago   254MB
debian       jessie        3aaeab7a4777   13 months ago   129MB


What’s the context path:

  • Docker build command takes the path on the build context as an argument
  • when build starts, docker client would pack all the files in the build context into a tarball then transfer the tarball file to the daemon
  • by default, dokcer would search for the Dockerfile in the build context path


  1. Docker
  2. Docker docs
  3. Getting started with Docker

My site is free of ads and trackers. Was this post helpful to you? Why not BuyMeACoffee