Docker Pipeline Taking Too Much Time to Finish?
I used to build docker image step by step, that’s before I found out about docker’s BuildKit. With the BuildKit
, the building time was reduced by 60% (in my case), I mean that’s crazy.
How Does the Concurrent Building Process Work?
Just split your Dockerfile into stages, the docker BuildKit will analyse all steps’ dependency of each other, and run multiple stages parallel. If a step does not depend on any other step, it will go straight forward. If a step depends on any other step, it will wait for its prerequisite to finish.
Here’s a piece of Dockerfile from my project:
1 | FROM shinchven/node:16-build |
All stages started at the same time, while step 3 of stage-2 waited for stage-0 and stage-1 to finish, because the --from=1
and --from=0
flag of COPY
command tells the step to wait for the stage-0 and stage-1 to finish. Thus, I saved a lot of time.
Use BuildKit
There are a few ways to use BuildKit:
1 | # Enable BuildKit for docker and docker-compose |
Please see official documentation for more details.