Live data from Hacker News

Optimising Docker Layers for Better Caching with Nix

grahamc.com

11–14 of 14 posts

Re: Optimising Docker Layers for Better Caching with Nix

#12

Neat. It seems like Nix could become the preferred way to build Docker images, if it's made a bit more user friendly. It's hard to beat the simplicity of FROM ubuntu:latest RUN apt-get update RUN apt-get install -y mysql php

"Simplest" can be subjective. There's not much that can compete with editing your nixos config file and adding services.mattermost.enable = true; and then running # nixos-rebuild switch to have a mattermost instance running.

I'm specifically talk about building a Docker container. The example in the article has a couple dozen lines of nix config and several shell commands.

Re: Optimising Docker Layers for Better Caching with Nix

#13
post #5

I really like this. I think it is a great compromise between the limitations of docker and everything packaged in one file while taking advantage of nix. I'm curious about one other optimization that could be made. You could instead look at the dependency graph of several nix docker builds and increase the cache reuse even more from that.

This approach is already optimal for up to around 40 or 120 packages, depending on whether you want to support old Docker versions.

"Where before you wouldn’t bother trying to have your application and database images share layers, with Nix the layer sharing is completely automatic."

Re: Optimising Docker Layers for Better Caching with Nix

#14
post #4

Nix and Docker integration is almost optimal now, no other tooling provides that type of functionality

[Habitat]( http://habitat.sh/ ) builds on the concepts in Nix, and here is a relatively old experiment I found on optimizing Docker layering with it: https://github.com/chetan/habitat-dockerize-layers

What I like about Nix is that this kind of functionality can be integrated into the Nixpkgs package set, as a function over packages. It's just as easy as writing a machine image or an virtual machine network test, because Nixpkgs has functions you can use for those as well.
Post reply on HN