Member-only story

Docker build: Cloning remote repository instead of copying build context

Görkem Gök
2 min readJan 10, 2021
“Docker-2” by maijou2501 is licensed under CC BY-SA 2.0

Understanding build context

Build context is the files and the directories under the PATH or URL which the Dockerfile is in.

Build context is the files that are used by Dockerfile to create the image. It can be a PATH or a URL. Dockerfile should be in the build context. It is not possible to use files from a top-level directory of the Dockerfile while building an image. That means that everything you need to create an image should be under the directory in which the Dockerfile is.

Dockerfile
src/
|
|- src-file-1
|- src-file-2
executables/
|
|- exec-file-1
|- exec-file-2

Copying files from the build context

We can copy the built executable to the image from the building context directly. In this case, we should build the source outside of the docker build.

$> build //creates the executables

Then we can use COPY command in Dockerfile:

COPY executables /executables
CMD ["executables/exec-file-1", "arg0"]

When we execute docker build , it will copy the executable file from the build context and create the image.

Downloading files

--

--

Görkem Gök
Görkem Gök

Written by Görkem Gök

Developer | Software Craftsmanship Enthusiast | Physicist

No responses yet