Docker image takes 3-4 times longer to build through Jenksin pipeline

Hi! I noticed that the same build task (e.g., building a docker image) takes much longer time (approx. 3-4 times) to complete through jenkins pipeline compared with running the task directly in a linux console on the same build server.

The performance gap appears to be too big. Is there any configuration or setting that can be tweaked to speed up the build performance?

are we talking 3-4 times longer than 1 second? or 3-4 times longer than 1 hour? There shouldn’t really be any reason things are taking drastically longer.

re docker image builds. do you have your .dockerignore setup to ignore all the extra files, on a different computer its usually why docker builds take longer than average (sending build context takes longer cause no files). The actual run (Which is done via cli) should be identical.

Let’s say it takes approx. 12 minutes to build a docker image if I invoke “docker build” command in the linux console on the jenkins server, it will take approx. 35 minutes to build the same image if the docker build command is invoked in Jenkins pipeline. I put time stamps in Jenkinsfile so I am sure that time taken through jenkinspipeline is much longer. Not sure why.

We don’t use .dockerignore.

The key is that it’s absolutely true that it takes much longer time for the same dockerfile to be built through command line and through Jenkins pipeline.

If you don’t use .dockerignore, then couldn’t that be a source of the performance difference, as mentioned by @halkeye ? I was using a git repository that contained large files and saw that my docker build times were regularly increasing as the repository size increased. The docker build process was seeing the large file copies that were in my .git directory. When I used a .dockerignore file to exclude the .git directory, my docker build processes became much faster.

3 Likes

A further difference can be docker caching. To compare performance run the commandline build with
–no-cache --pull to really build everthing.

3 Likes