Docker - Build (an image from a Dockerfile)

Card Puncher Data Processing


The build commands creates an image from a Dockerfile.

Command line


docker build [OPTIONS] PATH | URL | -

Build an image from a Dockerfile

      --build-arg value         Set build-time variables (default [])
      --cgroup-parent string    Optional parent cgroup for the container
      --cpu-period int          Limit the CPU CFS (Completely Fair Scheduler) period
      --cpu-quota int           Limit the CPU CFS (Completely Fair Scheduler) quota
  -c, --cpu-shares int          CPU shares (relative weight)
      --cpuset-cpus string      CPUs in which to allow execution (0-3, 0,1)
      --cpuset-mems string      MEMs in which to allow execution (0-3, 0,1)
      --disable-content-trust   Skip image verification (default true)
  -f, --file string             Name of the Dockerfile (Default is 'PATH/Dockerfile')
      --force-rm                Always remove intermediate containers
      --help                    Print usage
      --isolation string        Container isolation technology
      --label value             Set metadata for an image (default [])
  -m, --memory string           Memory limit
      --memory-swap string      Swap limit equal to memory plus swap: '-1' to enable unlimited swap
      --no-cache                Do not use cache when building the image
      --pull                    Always attempt to pull a newer version of the image
  -q, --quiet                   Suppress the build output and print image ID on success
      --rm                      Remove intermediate containers after a successful build (default true)
      --shm-size string         Size of /dev/shm, default value is 64MB
  -t, --tag value               Name and optionally a tag in the 'name:tag' format (default [])
      --ulimit value            Ulimit options (default [])


docker build -t "name:latest" .

Passing argument

See Dockerfile - ARG instruction (argument)



When building an image, the directory of the Dockerfile gives the build context.

You can then to attach the build to a continuous building software

  • create one directory by version with a different Dockerfile in each o them
  • create 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 .gitgnore file to exclude file from this context.

Example on Docker hub:

Docker Build Context

See build-context

Example with the -f flag to change the context to the dir newContextDir

docker build -t "gerardnico/imageName:tagName" -f newContextDir/Dockerfile .


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