Docker - Build (an image from a Dockerfile)

Card Puncher Data Processing


The build command 1) creates an image from:

  • and a build context 2): A build context is a list of files sent to the daemon. Example: All files from:
    • a directory if they are not in ignore file
    • a archive


Build an image

docker build -t "name:latest" .

where: with:

  • -t defines the image name name:latest
  • . defines the context as being the current directory
    • the Dockerfile is searched in this directory
    • All the files from the current directory are send to the daemon (without any .gitignore file restrictions)

How to minimize the context?

If the context is a whole code project, you can minimize the context data sent to the daemon with a docker ignore file .dockerignore that excludes all except the needed artifacts that you copy int

Example for a Java application:

# exclude all
# except

You can also specify a dockerignore file by Docker file

Command line


docker build [OPTIONS] PATH | URL | -

# example from stdin
docker build - < Dockerfile


  • the context is defined by:
    • PATH. All the files in the local directory get tard and sent to the Docker daemon.
    • or URL for:

Passing argument

See Dockerfile - ARG instruction (argument)



The context can be:

  • one directory by version with a different Dockerfile in each o them
  • a branch/or tag

All of the recursive contents of files and directories in the current directory are sent to the Docker daemon as the build context. You can add file in a .dockerignore file to exclude files from this context.

Example on Docker hub:

Docker Build Context


As each instruction is examined Docker looks for an existing image in its cache that it can reuse, rather than creating a new (duplicate) image. If you do not want to use the cache at all you can use the --no-cache=true option on the docker build command.


  • docker instruction based. RUN apt-get update if not modified will not be performed twice
  • hash file based. COPY will copy only if the hash of the file are note the same


  • A COPY instruction will get updated only when the files in the argument are updated.
  • An instruction with arguments will not get updated because the string stay the same

Documentation / Reference

Discover More
Card Puncher Data Processing
Docker - Continuous integration

Docker integration with continuous integration system in order to build and publish where: docker command: Travis System from Default-Environment-Variables...
Card Puncher Data Processing
Docker - Image

This page is the container image in Docker. OCI is the standardized container format used by Docker Docker stores downloaded images on the Docker host at the Docker Root Dir location where:...
Card Puncher Data Processing
Docker - docker client

The CLI uses the Docker REST API to control or interact with the Docker daemon where subcommand is: attach - Attach to a running container build - Build an image from a Dockerfile commit -...
Card Puncher Data Processing
Docker - dockerfile

A Dockerfile specifies instructions on how to create an image. See A Dockerfile describes the software that is “baked” into an image. It isn’t just ingredients though, it can tell the software...
Card Puncher Data Processing
DockerFile - Instruction

Basis Image: Tool installation (note: the package are sorted in alphabetical order) More ... Defines argument that can be passed by the build command line ...
Card Puncher Data Processing
Dockerfile - ARG instruction (argument)

ARG defines argument that can be passed by the build command line Defines an argument in your docker file Pass a new value via the build command

Share this page:
Follow us:
Task Runner