Docker

What Does it Mean Sending Build Context to Docker Daemon

Docker build is one of the command line utilities provided by the Docker CLI. The “docker build” command generates the image by reading instructions from the Dockerfile and a context. The build command sends the Docker Daemon the build context (Collection of files on a specific path). Then, these files or contexts are used by Docker image to encapsulate the project.

This write-up will demonstrate:

What Does Sending Build Context to Docker Daemon Mean?

The process of sending files and directories from the local repository to the Docker Daemon during building an image is called sending build context to the Docker daemon. To generate the image, a Docker daemon is required to access the files, and these files are placed in the same directory where Dockerfile is placed. More specifically, the “build” command reads the file’s location from Dockerfile instructions and sends the build context to Docker Daemon.

How to Send Build Context to Daemon in Docker?

To send the build context to Docker Daemon, simply utilize the “docker build” command. This command will access the context location from Dockerfile and send the context or files to Docker Daemon. The project location can contain several files and sub-directories that may not be required to send to Docker Daemon. These files can be ignored using the “.dockerignore” file.

For the illustration, go through the given instructions.

Step 1: Ignore Files

First, create a “.dockerignore” file to ignore the files that are not required to build or create an image. Add the name of files into the “.dockerignore” file to ignore them:

Step 2: Send Build Context to Daemon

Next, send the build context to Docker Daemon using the “docker build -t <image-name> .” command. Here, “.” is used to specify that read the Dockerfile and build context from the currently open directory:

docker build -t go-image .

From the output, you can see that Dockerfile and other build contexts are transferring to Docker daemon:

Step 3: Run Image

For the verification, run the image created by sending the build context to Daemon using the provided command. Here “-p” option is used to specify the exposing port and “-d” for running the container in detached mode:

docker run -d -p 8080:8080 go-image

After that, open the local host assigned port and check if the container is executing or not. Here, you can see, we have successfully built and executed the image:

We have demonstrated what does sending build context means and how to send it to Daemon.

Conclusion

Sending build context to the Docker daemon means the process of sending files and directories from the local repository to the Docker Daemon during building an image. To send the build context to Docker Daemon, simply utilize the “docker build” command. This command will access the context location from Dockerfile and send the context or files to Docker Daemon. This write-up has demonstrated what sending build context means and how to send it to Daemon.

About the author

Rafia Zafar

I am graduated in computer science. I am a junior technical author here and passionate about Programming and learning new technologies. I have worked in JAVA, HTML 5, CSS3, Bootstrap, and PHP.