# Docker build speed up

**URL:** <https://forums.docker.com/t/docker-build-speed-up/72068>\
**Category:** General\
**Created:** [March 28, 2019, 12:29pm UTC](https://forums.docker.com/t/docker-build-speed-up/72068 "2019-03-28T12:29:32Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![danishsultan007](https://avatars.discourse-cdn.com/v4/letter/d/a8b319/32.png) [@danishsultan007](https://forums.docker.com/u/danishsultan007)\
**Post date:** [March 28, 2019, 12:29pm UTC](https://forums.docker.com/t/docker-build-speed-up/72068/1 "2019-03-28T12:29:32Z")

</div>

I am new to docker and how it works. I wanted to know where do i keep my Dockerfile and also does it really even matter where i keep it?

Previously i used to keep my Dockerfile inside the project root directory for example

Project1–  
+src–  
+dist–  
+.gitignore  
+index.php  
+Dockerfile  
Project2–  
+src–  
+dist–  
+node\_modules–  
+.gitignore  
+index.php  
+Dockerfile  
+docker-entrypoint.sh  
+package.json

The speed of the build when i used to build it from the project root folder would start like this  
$ sudo docker build -t name .

Sending build context to Docker daemon 2.036MB \<----this going in GBs which used to take like 20-25 mins in hp-intel i3, 4gig, linux mint machine

This has wasted my time for weeks.

Then while experimenting randomly, when i moved the Dockerfile from the root directory to a subfolder naming docker or anything like that for example

Project1–  
+src–  
+dist–  
+.gitignore  
+index.php  
+Docker–  
+Dockerfile  
Project2–  
+src–  
+dist–  
+node\_modules–  
+.gitignore  
+index.php  
+Docker–  
+Dockerfile  
+docker-entrypoint.sh  
+package.json

the build speed went to seconds from 30mins went to seconds  
when i ran the build command

Sending build context to Docker daemon 3.584kB

Step 1/3 :  
----\> 525fcb69c27c  
Step 2/3 :  
----\> f86fcb69c27c  
Step 3/3 :  
----\> 865fcb69c27e

Successfully built 9c67c87cd

This happens now in seconds like max 10 seconds the context to docker daemon completed and starts executing my steps in the containers.

Please tell me what is happening here? What is sending build context to docker daemon?  
Why it used to go in GBs (1.8 or 2.4gbs on an average) when i kept the dockerfile in the root folder and when i shifted it to a subfolder it went to kbs??

does it sends the project files and subfolders to docker daemon??is that why it takes time? is this the correct approach that i am doing now? also what if i had to copy something inside my docker container using COPY or ADD will it be a problem if i place it somewhere else other than my project root folder?

---

<div class="post-metadata">

**Author:** ![nodrojelmo](https://avatars.discourse-cdn.com/v4/letter/n/65b543/32.png) [@nodrojelmo](https://forums.docker.com/u/nodrojelmo)\
**Post date:** [April 9, 2019, 2:06pm UTC](https://forums.docker.com/t/docker-build-speed-up/72068/2 "2019-04-09T14:06:56Z")

</div>

Yes you can. Create two images

**Dockerfile-base**

```auto
FROM python:3.6
RUN pip install selenium

```

Then build using below

```auto
docker build -f Dockerfile-base -t base .

```

**Dockerfile**

```auto
FROM base
COPY . .

```

So you won’t rebuild base. And keep on working on the main Dockerfile. There are other possible solutions also like deploying local **Nexus package manager** and using it to cache packages locally. But then too much of effort for a developer machine.

Regards,  
_Nodro Jelmo_
