Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I haven't used java in over a decade so won't be able to help much with that, but for example I was able to get my application to fit in just 70MB container including python and all dependencies + busybox and tini

It looked something like this: https://gist.github.com/takeda/17b6b645ad4758d5aaf472b84447b...

So what I did was:

- link everything with musl

- compile python and disable all packages that I didn't use in my application

- trim boto3/botocore, to remove all stuff I did not use, that sucker on it's own is over 100MB

The thing is what you need to understand is that the packages are primarily targeting the NixOS operating system, where in normal situation you have plenty of disk space, and you rather want all features to be available (because why not?). So you end up with bunch of dependencies, that you don't need. Alpine image for example was designed to be for docker, so the goal with all packages is to disable extra bells and whistles.

This is why your result is bigger.

To build a small image you will need to use override and disable all that unnecessary shit. Look at zulu for example:

https://github.com/NixOS/nixpkgs/blob/master/pkgs/developmen...

you add alsa, fontconfig (probably comes with entire X11), freetype, xorg (oh, nvm fontconfig, it's added explicitly), cups, gtk, cairo and ffmpeg)

Notice how your friend carefully extracts and places only needed files in the container, while you just bundle the entire zulu package with all of its dependencies in your project.

Edit: tadfisher seems to be more familiar with it than me, so I would start with that advice and modify code so it only includes a single jdk. Then things that I mentioned could cut the size of jdk further.

Edit2: noticed another comment from tadfisher about openjdk_headless, so things might be even simpler than I thought.



I've never used Nix, but this looks like hell'a of an unreadable config file (compared to docker)? How do you manage these files?


This does far more than Dockerfile though.

- it contains information how to actually build the application

- how to set up a dev environment

- how to build application with musl

- how to build application with glibc

- how to build python with only with expat, libffi, openssl, zlib packages

- how to take botocore and patch it up to only have cloudformation, dynamodb, ec2, elbv2, ssm, sso, sts clients

Try to get all of that into a single Dockerfile and see how complicated mess you end up with.

The actual docker configuration is here:

https://gist.github.com/takeda/17b6b645ad4758d5aaf472b84447b...

It might be still confusing to you at first, as you're used to list of incremental steps how to get to the final result, while this description instead is declarative (you're describing not the steps to do, but what the final image should be).

It's basically comparing bash script with bunch of "aws" CLI invocations to a terraform or cloudformation file.


It's not actually unreadable - you just have to learn convention on top of the Nix language. For instance, what mkDerivation does. Actually, the Nix language usage here is somewhat minimal. Mostly let bindings (aka lambda calculus).

I wouldn't expect a layman to be able to grok that file. That's fine though - it's not for laymen.


> It's not actually unreadable - you just have to learn convention on top of the Nix language. For instance, what mkDerivation does. Actually, the Nix language usage here is somewhat minimal. Mostly let bindings (aka lambda calculus).

> I wouldn't expect a layman to be able to grok that file. That's fine though - it's not for laymen.

This is the kind of comment that makes me want to stay far, far away from Nix and the Nix "community".


Why? Saying that Nix is complicated and isn't trivial to use or read without learning prerequisite knowledge is bad now?

I actually pointed out that mkDerivation is something helpful to learn - that's one thing I wish someone made me sit and learn when I first got exposed to Nix. It unlocks a lot.


I wouldn't state it's _bad_. It just adds another layer of complexity (by, for sure, also giving something back) and as someone not working in Fortune 500 (but rather in a SME with <20 people), another layer of conplexity & another language is sonetimes just not feasable.


I think whateveracct was referring to is this link:

https://github.com/NixOS/nixpkgs/blob/master/pkgs/developmen...

What that file is doing, is building a package, and it essentially is a combination of what Makefile and what RPM spec file does.

I don't know if you're familiar with those tools, but if you aren't it takes some time to know them enough to understand what is happening. So why would be different here?


What do you mean by manage?

I agree with your assertion regarding the language though. I think nix-lang makes it harder to get into Nix.


You are correct. I havent done any trimming. Thanks for the suggestions and the gist. Thanks


I found this discussion and contains code fragments and links that might help.

https://discourse.nixos.org/t/how-to-create-a-docker-image-w...




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: