Member-only story

Docker Tips: All About the Build Context

Understand what the build context is and how to optimize it

Luc Juggery
Better Programming
5 min readOct 19, 2018

--

Let’s check out this build context thing!

What Is the Build Context?

Let’s start with the command used to build a Docker image:

$ docker build [OPTIONS] PATH | URL | -

The build context is the set of files located at the specified PATH or URL. Those files are sent to the Docker daemon during the build so it can use them in the filesystem of the image.

Let’s illustrate this.

Using a path

Let’s suppose I’m in the folder /Users/luc/src/github.com/lucj/genx containing the source code of the genx application (simple Go application that generates dummy data).

Usually, we use a command like the following one to build the image, the Dockerfile being at the root of the project’s folder:

$ docker image build -t genx:1.0 .

In that case, the build context is the content of the current folder (“.” specified as the last element of the command).

Using a URL

This same genx project is managed in GitLab, so it’s possible to build an image locally referencing the GitLab repository:

$ docker image build…

--

--

Luc Juggery
Luc Juggery

Written by Luc Juggery

Docker & Kubernetes trainer (CKA / CKAD), 中文学生, Learning&Sharing

Responses (1)

Write a response