Docker Community Forums

Share and learn in the Docker community.

Docker build speed up

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?

Yes you can. Create two images

Dockerfile-base

FROM python:3.6
RUN pip install selenium

Then build using below

docker build -f Dockerfile-base -t base .

Dockerfile

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