-
Notifications
You must be signed in to change notification settings - Fork 158
How to optimize Docker image size? #45
Comments
I've never tried solving for docker image size, but, I can give you some thoughts:
I plan to switch the OSS CI build to static linking at some point, which would help your use-case. Unfortunately, it's hard to for me to predict how long this will take, because I'm bad at CMake and there are some hurdles. Internally, statically linked binaries go like this:
The upshot here is that if you're willing to lose useful backtraces, you can probably get these to be pretty small. |
Good start, not sure which are those though 😄
I am limited with my c++ knowledge. I have not found I just made very quick test with dockerfile like this (it is common multi-stage strategy to optimize buildes, so i have builder image + the real carrying only executables):
But as expected it fails on some missing dependencies, mine was:
There was just an idea, if i could copy everything needed & compiled things into new image without any unnecessary stuff.
I even tried to remove everything except
I am very experienced with docker and capable of optimizing the build, but unfortunately my c++ knowledge is slowing me down 😄 |
After removing files via
It still works. Now i need to know what can be deleted from distro (probably source codes as well, logs etc., i rather what should be kept instead of what should be deleted is easier approach). Next step will be other system thins and dependenciesm not sure which are those yet. What difference will make running |
FYI, so far after removing for non-bistro everything except .so results: Before:
After:
Not bad for just a start. |
If there's no
This is fine,
All build artifacts get installed in So you should not need any of the build trees at all, just For the OS, you could do things like An alternative approach is to find the smallest base OS of the same Ubuntu release that you can get, copy over Either way, it'd be a bit of a trial and error, I've never the time to separate the runtime dependencies from the build-time dependencies for the OSS build. If you find time to upstream your work, that would be lovely. If not, maybe at least share a gist of your process on this issue? |
Hi, i was finally able to build a Docker image with Bistro, but i am a bit worried about it's enormous size. It has roughly 5.2gb.
Do you have any tips how to reduce it's size?
It is automatically generated Dockerfile using fbcode_builder.
Basically it is repeating blocks of download+build+install blocks:
I was thinking if i can somehow remove cache. Maybe just
rm -rf /fmt
(same for every other cloned repository) after package is installed could help to reduce size.As well i do not usually use c++ so i do not know how it really works internally, please if i am mistaken and my idea is stupid, just correct me 😄 if we could take only the final binaries and extract them to different, clean, docker image?
Other idea was using some alpine based linux or other base image than ubuntu (quick googling brought me to https://github.com/madduci/docker-cpp-env).
Can anything of this work or would you suggest anything completely different?
I was thinking about having autoscaling mechanism for bistro workers etc on aws spot instances (maybe even as lambdas) and for these purposes i wanted to have image as thin as possible.
The text was updated successfully, but these errors were encountered: