skip to Main Content

Sometimes we face some nginx vulnerabilities,
so we need to fix the nginx vulnerabilities inside ingress-nginx,
but the docker build -t image is too slow.
The reason is that the dockerfile internal will make compile and make install process.
How to add some parameters can make the docker build process faster?

Although the docker build process prompts make to add the -j parameter to increase threads to speed up the process,
there is no make related parameter inside the dockerfile.
It is not a good idea to modify the dockerfile directly.

Source of the dockerfile.

2

Answers


  1. Chosen as BEST ANSWER

    enter image description here

    docker version: docker-ce.20.10

    Actual testing of images made by buildkit
    may actually do little to improve the efficiency of making images if they involve a lot of compilation processes internally.
    Maybe based on the official alpine base image,
    consider add the -j nproc parameter in dockerfile to increase the threads, would be a good direction.


  2. There is no one good solution on how to speed up the building of a Docker image. This may depend on a number of things. That is why I am posting the answer of the community wiki to present as many solution proposals as possible, referring to various tutorials.


    There are a few tricks you can use to speed up building Docker images.
    First I will present you solution from Google cloud:

    The easiest way to increase the speed of your Docker image build is by specifying a cached image that can be used for subsequent builds. You can specify the cached image by adding the --cache-from argument in your build config file, which will instruct Docker to build using that image as a cache source.

    You can read more here about Docker Layer Caching.

    Another way is Structure your Dockerfile instructions like an inverted pyramid:

    Each instruction in your Dockerfile results in an image layer being created. Docker uses layers to reuse work, and save bandwidth. Layers are cached and don’t need to be recomputed if:

    • All previous layers are unchanged.
    • In case of COPY instructions: the files/folders are unchanged.
    • In case of all other instructions: the command text is unchanged.

    To make good use of the Docker cache, it’s a good idea to try and put layers where lots of slow work needs to happen, but which change infrequently early in your Dockerfile, and put quickly-changing and fast layers last. The result is like an inverted pyramid.

    You can also Only copy files which are needed for the next step.

    Look at these great tutorials about speeding building your Docker images:

    5 Tips to Speed up Your Docker Image Build
    Speed Up Your Development Flow With These Dockerfile Best Practices
    -[Six Ways to Build Docker Images Faster (Even in Seconds)](# Six Ways to Build Docker Images Faster (Even in Seconds)

    At the end I will present you one more method described here – How to speed up your Docker image build? You can you a tool Buildkit.

    With Docker 18.09 ,a new builder was released. It’s called Buildkit. It is not used by default, so most of us are still using the old one. The thing is, Buildkit is much faster, even for such simple images!

    The difference is about 18 seconds on an image that builds in the 70s. That’s a lot, almost 33%!

    Hope it helps 😉

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search