• Home
  • LLMs
  • Python
  • Docker
  • Kubernetes
  • Java
  • Maven
  • All
  • About
Docker | Docker CLI: Docker Build Command
  1. Docker Build Command
  2. Usage
  3. Options

  1. Docker Build Command
    The Docker CLI (Command-Line Interface) docker build builds an image from a Dockerfile.
    To list the command options, type: docker build --help

    Docker introduced a new backend for building images called Buildkit, which does not expose intermediate build steps in the same way as the legacy builder. To view intermediate build steps and containers using the legacy builder, set the environment variable DOCKER_BUILDKIT=0 before using the docker build command:
    $ DOCKER_BUILDKIT=0 docker build [OPTIONS] PATH | URL | -
    This disables Docker BuildKit, which is now the default builder and offers improved performance, output, and caching. It's recommended to enable BuildKit (DOCKER_BUILDKIT=1) or simply omit the variable.
  2. Usage
    Usage: docker build [OPTIONS] PATH | URL | -
  3. Options
      -t, --tag list                Name and optionally a tag in the 'name:tag' format
    
      -f, --file string             Name of the Dockerfile (Default is 'PATH/Dockerfile')
    
      -q, --quiet                   Suppress the build output and print image ID on success
    
          --no-cache                Do not use cache when building the image
          --cache-from strings      Images to consider as cache sources
    
          --pull                    Always attempt to pull a newer version of the image
    
          --build-arg list          Set build-time variables
    
          --add-host list           Add a custom host-to-IP mapping (host:ip)
    
          --rm                      Remove intermediate containers after a successful build (default true)
          --force-rm                Always remove intermediate containers
    
          --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)
    
      -m, --memory bytes            Memory limit
          --memory-swap bytes       Swap limit equal to memory plus swap: '-1' to enable unlimited swap
    
          --cgroup-parent string    Optional parent cgroup for the container
          --compress                Compress the build context using gzip
          --disable-content-trust   Skip image verification (default true)
          --iidfile string          Write the image ID to the file
          --isolation string        Container isolation technology
          --label list              Set metadata for an image
          --network string          Set the networking mode for the RUN instructions during build (default "default")
      -o, --output stringArray      Output destination (format: type=local,dest=path)
          --platform string         Set platform if server is multi-platform capable
          --progress string         Set type of progress output (auto, plain, tty). Use plain to show container output (default "auto")
          --secret stringArray      Secret file to expose to the build (only if BuildKit enabled): id=mysecret,src=/local/secret
          --security-opt strings    Security options
          --shm-size bytes          Size of /dev/shm
          --squash                  Squash newly built layers into a single new layer
          --ssh stringArray         SSH agent socket or keys to expose to the build (only if BuildKit enabled) (format: default|<id>[=<socket>|<key>[,<key>]])
          --stream                  Stream attaches to server to negotiate build context
          --target string           Set the target build stage to build.
          --ulimit ulimit           Ulimit options (default [])
© 2025  mtitek