• Home
  • LLMs
  • Docker
  • Kubernetes
  • Java
  • Ubuntu
  • Maven
  • Archived
  • About
Docker | Docker CLI: docker build command
  1. docker build command
  2. Usage
  3. Options
  4. --no-cache
  5. -f FILE_NAME|FILE_LOCATION
  6. --build-arg

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

    Docker introduced new backend for builing images (buildkit) which doesn't expose intermediate containers.
    To show intermediate containers, set the environment variable DOCKER_BUILDKIT before the docker build command:
  2. Usage
    Usage: docker build [OPTIONS] PATH | URL | -
  3. Options
  4. --no-cache
    You can use the option '--no-cache' to instruct Docker to not use cache when building the image:

    Let's use this Dockerfile:

    The first time we build the Dockerfile we will get the following output:

    If we build again the Dockerfile we will get the following output:

    You can notice that the step 2 has the mention '---> Using cache' which means that Docker just used the already built layer from this step.

    Using local cache can speed up build time; especially when avoiding rebuilding image layers that take long time to build or take up large amounts of disk space.

    In some cases (either to play safe or because we encountered some issues with the build) we might want to disable the cache, for that we use the option --no-cache:


    You can notice that the step 2 has the mention '---> Running' which means that Docker is rebuilding again the image layer for that step.
  5. -f FILE_NAME | FILE_LOCATION
    By default Docker will use the Dockerfile in the current directory ('./Dockerfile'). You can use the option '-f FILE_NAME|FILE_LOCATION' to let Docker use a Dockerfile with a different name and/or a different path.

    Let's create a Dockerfile named 'Dockerfile1':

    To use the Dockerfile 'Dockerfile1' (located in the current directory):

    You can also provide the full path where Dockerfile1 is located (e.g. '/opt/dockerfiles/'):
  6. --build-arg
    You can use the option '--build-arg' to set build arguments.

    Let's use this Dokerfile:

    Note that the arguments are used as variables in the Dockerfile using the syntax '$ARG_NAME'

    If you don't specify a value for an argument in the build command, then the default values in the Dockerfile will be used:

    To pass new values for the arguments, use the option '--build-arg':

    Check that the arguments were used as expected:
© 2025  mtitek