7 ms·
> Also, build times and sizes don't matter too much in the grand scheme of things. Unless you're changing the Dockerfile regularly, it won't matter. Why? Becaus
by throwaway894345 7y ago
> Also, build times and sizes don't matter too much in the grand scheme of things. Unless you're changing the Dockerfile regularly, it won't matter. Why? Because Docker caches each layer of the build.
It does if you practice continuous deployment, or even if you use Docker in your local dev setup and you want to use a sane workflow (like `docker-compose build && docker-compose up` or something). Unfortunately, the standard docker tools are really poorly thought out, beginning with the Dockerfile build system (assumes a linear dependency tree, no abstraction whatsoever, standard tools have no idea how to build the base images they depend on, etc). It's absolute madness. Never mind that Docker for Mac or whatever it's called these days will grind your $1500 MacBook Pro to a halt if you have a container idling in the background (with a volume mount?). Hopefully you don't also need to run Slack or any other Electron app at the same time.
As for the build cache, it often fails in surprising ways. This is probably something on our end (and for our CI issues, on CircleCI's end [as far as anyone can tell, their build cache is completely broken for us and their support engineers couldn't figure it out and eventually gave up]), but when this happens it's a big effort to figure out what the specific problem is.
This stuff is hard, but a few obvious things could be improved--Dockerfiles need to be able to express the full dependency graph (like Bazel or similar) and not assume linearity. Dockerfiles should also allow you to depend on or include another Dockerfile (note the differences between including another Dockerfile and including a base image). Coupled with build args, this would probably allow enough abstraction to be useful in the general case (albeit a real, expression-based configuration language is almost certainly the ideal state). Beyond that the standard tooling should understand how to build base images (maybe this is a byproduct of the include-other-Dockerfiles work above) so you can use a sane development workflow. And lastly, local dev performance issues should be addressed or at least allow for better debugging.
- codereflection 7y agoSpeaking of best practices for Dockerfiles and CI/CD, a lot of these issues can be highlighted at build time with a Docker linter like https://github.com/hadolint/hadolint https://github.com/hadolint/hadolint.
- throwaway894345 7y agoI didn't know about hadolint, but I don't see how it (or any other linter) can address any of these issues (unless "these issues" is not referring to the issues I was mentioning in the post you responded to).
- dunk010 7y agoHadolint is nice. Hadolint addresses none of the major issues you raise.
- codereflection 7y agoHadolint will tell about things like adding --no-cache to apk add. My point being that comments were made about not following best practices, and hadolint will help with that.
- kortilla 7y agoYeah, you replied to the wrong post. You should have replied to the parent of the one you replied to.
- codereflection 7y agoYep
- jacques_chester 7y agoOr, and I am biased here, use Cloud Native Buildpacks and never think about this stuff again.
- throwaway894345 7y agoI'm not familiar, can you elaborate on how those solve these problems? I'm always looking for a better way of doing things.
- jacques_chester 7y agoBroadly, CNBs are designed to intelligently turn sourcecode into images. The idea of buildpacks isn't new, Heroku pioneered it and it was picked up in other places too. What's new is taking full advantage of the OCI image and registry standards. For example, a buildpack can determine that a layer doesn't need to be rebuilt and just skip it. Or it can replace a layer. It can do this without triggering rebuilds of other layers. Finally, when updating an image in a registry, buildpacks can perform "layer rebasing", creating new images by stamping out a definition with a changed layer. If all your images are built with buildpacks, you reduce hours of docker builds to a few seconds of API calls. This is a bit of a word soup, so I'll point you to https://buildpacks.io/ https://buildpacks.io/ for more.
- jonhohle 7y agoI've built some docker build infrastructure which attempts to optimize build times and reduce cost of incremental builds. I was able to take a monolithic binary artifact which cost around 350mb per build down to less than 40mb by more intelligent layering. If you haven't found it already, `--cache-from` with the previously built stable image makes this relatively painless. I've been considering writing a merge tool to support fork/merge semantics, focussing more on development and debugging than build-time optimization.
- viraptor 7y ago> Never mind that Docker for Mac or whatever it's called these days will grind your $1500 MacBook Pro to a halt if you have a container idling in the background (with a volume mount?). Hopefully you don't also need to run Slack or any other Electron app at the same time. Just in case anyone is wondering, this is a great exaggeration. Idling containers are close to idling (~2%cpu currently), and slack got pretty small last year. These work just fine, I wish the trope died already.
- deleted 7y ago[deleted]
- dockerformax 7y agoThis is because there is no native support on Mac for docker. Everything has to run in a virtualized environment that's basically a slightly more efficient version of VirtualBox. When people say docker is lightweight and they're running it on a Mac they don't quiet understand what they're saying. Docker is lightweight on baremetal linux, it's not lightweight on other platforms because the necessary kernel features don't exist anywhere except linux.
- viraptor 7y agoIt's true that the overhead is larger on macos. And you're right it doesn't run natively there. But it's not like idle hardware virtualised process is less idle than a native one. Sure, there may be extra events waking up the kernel itself. But let's not exaggerate the impact. There's no grinding to a halt from an idle container.
- cpuguy83 7y agoDocker's build system has been given a huge overhaul and does create a dependency tree. It is highly efficient and even does things like support mounts for caching package downloads, build artifacts, etc. See https://github.com/moby/buildkit https://github.com/moby/buildkit. You can enable it today with `DOCKER_BUILDKIT=1 docker build ...` There is also buildx which is an experimental tool to replace `docker build` with a new CLI: https://github.com/docker/buildx https://github.com/docker/buildx
- throwaway894345 7y agoI don't see how buildkit could possibly build the correct dependency tree because the Dockerfile language doesn't let you express nonlinear dependencies. If you have a command `do_foo` that depends on do_bar and do_baz (but do_bar and do_baz are independent) and you do something like: RUN do_bar # line 1 RUN do_baz # line 2 RUN do_foo # line 3 I'm guessing the buildkit dep graph will look like `line_3 -> line_2 -> line_1` (linear). Unless there is some new way of expressing to Docker that do_foo depends on do_bar and do_baz but that the latter two are independent. EDIT: clarified example.
- cpuguy83 7y agoDependcies are also for multiple stages, e.g.: So `COPY --from=<some stage>` and `FROM <other stage>` Also, a Dockerfile is just a frontend for buildkit. The heart of buildkit is "LLB" (sort of like LLVM IR in usage) which is what the Dockerfile compiles into. Buildkit just executes LLB, doesn't have to be from a Dockerfile. For that matter you can have a "Dockerfile" (in name only) that is not even really dockerfile since the format lets you specify frontend to use (which would be a container image reference) to process it. There's even a buildkit frontend to build buildpacks: https://github.com/tonistiigi/buildkit-pack https://github.com/tonistiigi/buildkit-pack Works with any buildkit enabled builder, even `docker build`.
- throwaway894345 7y agoYeah, there are a lot of workarounds when you leave the standard tooling. I like the idea of using something like Bazel to build Docker images (since modeling dependencies and caching build steps is its raison d'etre) and eschewing Dockerfiles altogether; however, I haven't tried it (and Bazel has its own costs). I'm not familiar with buildkit in particular, but it's cool that it has an internal representation. I'll have to dig around.
- giovannibonetti 7y ago> As for the build cache, it often fails in surprising ways. This is probably something on our end (and for our CI issues, on CircleCI's end We have been using Google Cloud Build in production for over an year and Docker caching [1] works great. And Cloud Build is way cheaper than CircleCI. I recommend it, and I'm not getting paid anything for it. [1] https://cloud.google.com/cloud-build/docs/speeding-up-builds#using_a_cached_docker_image https://cloud.google.com/cloud-build/docs/speeding-up-builds...
- souronly9282 7y agoBuilt CI/CD at various places and image build time doesn’t matter. This is one of those subjective things where shaving every minute feels important but does nothing to reduce real costs or increase revenue. If the business isn’t selling the product faster in exchange, you’re prematurely optimizing. In fact spending time on such nickle and diming of deploy times often leaves other useful work untouched. I see it all the time at places big and small as a contractor. Gravity towards easy wins (cruft removal from Docker images) sees useful but trickier work go untouched. It’s pure emotional masturbation. Then you call out how your own CD/CI pipeline is probably causing issues, and software bloat in general. All that text about Docker and only one real problem attributed to Docker for Mac (the industry itself writes bloated software, I can’t knock Docker low effort in engineering when that’s a feature of society.) No Dockerfiles do not need to express a dependency graph. This is how bloated software gets made: every little design consideration need not be jammed into the design of one particular piece of software. Swiss Army knife tooling leads us to Slack in Electron which you also complained about. Images are reviewable. Make it a part of your life to smooth out bumps as you need. The rest of us don’t need to import your preferences in the core tools to correct for deficiencies in your workflow alone.