Docker Consulting Services And Slow Builds

Long build times waste time and patience. See how Docker consulting services can spot the causes and make your builds faster.

Docker Consulting Services And Slow Builds

Our Docker Consulting Services review found a container build taking twenty eight minutes. Engineers started a build, went to do something else, and came back having lost the thread of what they were doing.

It is now about ninety seconds for most changes, and nothing about the application changed. Here is what Docker Consulting Services should fix first on a slow build.

Measure each layer before changing anything

Because the slow part is rarely where people assume.

Ours spent nineteen of its twenty eight minutes installing dependencies, which had not changed in four months.

We had been optimising the application copy step, because that was the part people understood.

Order the instructions by how often they change

The single highest return change.

Anything that changes rarely goes near the top. Anything that changes every commit goes at the bottom.

Our application code was copied before the dependency install, which invalidated the cache on every build. Moving two lines took the common case from twenty eight minutes to about four.

Use a multi stage build

So the shipped image is not the build environment.

Compilers, build tools, test dependencies, and source code all belong in a stage that does not reach production.

Ours went from one point two gigabytes to about one hundred and eighty megabytes. That is faster to push, faster to pull, and a smaller attack surface.

Pick a small base deliberately

Rather than inheriting one.

A full distribution base brings hundreds of packages, most of which your application never calls, all of which need patching and scanning.

We moved to a minimal base and spent two days finding the four things we genuinely needed. Our vulnerability count fell by about ninety per cent and almost none of those were ever reachable.

Cache dependencies across builds

Properly, not accidentally.

A mounted cache for the package manager means a dependency downloaded once is not downloaded again on a different machine.

Ours shaved a further ninety seconds off and cost about an hour to set up.

Keep the context small

Because everything in the directory gets sent.

Our build was transferring a test data directory of about four hundred megabytes on every run, for no reason.

An exclusion file fixed that in five minutes. A partner should ask about this before anything else, because it is free.

Pin the base by digest

Not by tag.

A tag moves. Two builds a month apart from identical source can contain different base images and nobody records it.

Ours pins by digest and updates deliberately, which also means a base image change appears in a pull request rather than happening silently.

Do not run as root

A default worth changing.

Our images ran as root because that is what happens if nobody says otherwise.

Creating a user and switching to it is three lines and removes a category of finding from every scan we run.

Decide what the image is for

Which shapes the whole discussion.

Our monolith image contains one application. Had we split that estate into services, we would have twenty images with twenty build pipelines and twenty sets of this work.

The monolithic vs microservices question is partly a build and operations question, and the image count is a cost people discover afterwards. Our Java App Development Company partner raised that early, which saved us from a split we were not staffed for.

Scan at build and at publish

Two different moments.

The build scan tells you what you assembled. The publish scan, run again before promotion, catches anything disclosed in between.

Ours caught one image that passed at build and failed four days later at publish. That is the whole argument for doing both.

What our build practice covers

●        Per layer timing measured before any optimisation.

●        Instructions ordered by how often each one changes.

●        Multi stage builds keeping tooling out of the shipped image.

●        A deliberately minimal base with only what is needed.

●        A mounted package cache shared across builds.

●        A context exclusion file keeping transfers small.

●        Base images pinned by digest and updated deliberately.

●        A non root user in every image.

●        Vulnerability scanning at both build and publish.

Common Questions

Where does build time actually go?

Dependency installation, usually, invalidated by a badly ordered copy step. Ours was nineteen of twenty eight minutes.

What is the quickest win?

Instruction order. Two lines took our common build from twenty eight minutes to four.

Does image size matter?

For pull time, storage, and scanning surface. Ours went from one point two gigabytes to one hundred and eighty megabytes.

Why pin by digest?

Because tags move. Docker Consulting Services inheriting a tag based estate will find builds that differ from identical source.

What about image size?

Ours went from one point two gigabytes to one hundred and eighty megabytes once the build stages were separated.

Does a partner need to stay?

Not for this. Good Docker Consulting Services leave you with a build definition your own team can read and change.

Who should own the build definition?

A platform team, reviewed. An engagement that optimises once and leaves will find the same twenty eight minutes in two years.

Does the application language matter?

It shapes the layers. Our Java App Development Company colleagues cache dependencies differently from our other teams, and both benefit from the same ordering rule.

What does a partner check first?

Context size and instruction order. Both are free, and good Docker Consulting Services ask about them before anything else.

Does the architecture affect this?

Considerably. Twenty services means twenty of everything in this piece, which is a cost worth counting before splitting.

Where we are now

Ninety second builds for the common case, one hundred and eighty megabyte images, digest pinned bases, a non root user, and scanning at both build and publish.

The twenty eight minutes were not caused by anything complicated. Two lines were in the wrong order and had been for about three years.