4 ms·
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 inc
by takeda 3y ago
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/17b6b645ad4758d5aaf472b84447bb7c 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/development/compilers/zulu/common.nix 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.
- jossephus01 3y agoYou are correct. I havent done any trimming. Thanks for the suggestions and the gist. Thanks
- takeda 3y agoI found this discussion and contains code fragments and links that might help. https://discourse.nixos.org/t/how-to-create-a-docker-image-with-minimal-jdk-11-there-is-no-jre11-headless/11849 https://discourse.nixos.org/t/how-to-create-a-docker-image-w...
- chrisandchris 3y agoI've never used Nix, but this looks like hell'a of an unreadable config file (compared to docker)? How do you manage these files?
- elbear 3y agoWhat 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.
- whateveracct 3y agoIt'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.
- guitarbill 3y ago> 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".
- whateveracct 3y agoWhy? 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.
- chrisandchris 3y agoI 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.