Table of Contents

Docker - Build (an image from a Dockerfile)

About

The build command 1) creates an image from:

Example

Build an image

docker build -t "name:latest" .

where: with:

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
!build\libs\bytle-smtp-server-all.jar
!conf\**

You can also specify a dockerignore file by Docker file

Command line

Syntax

docker build [OPTIONS] PATH | URL | -

# example from stdin
docker build - < Dockerfile

where:

Passing argument

See Dockerfile - ARG instruction (argument)

Code

Context

The context can be:

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

Cache

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.

CACHE is:

Example:

Documentation / Reference