lncm / docker-bitcoind

Flexible multi-arch (amd & amd64) Bitcoin Core Docker image
https://hub.docker.com/r/lncm/bitcoind
MIT License
102 stars 34 forks source link

Image size reduction #20

Closed lukechilds closed 4 years ago

lukechilds commented 4 years ago

Copying /opt directly over from the build stage to the final image ends up with a load of build stage dependencies from Berkley DB and Bitcoin Core bloating the image that aren't required at runtime.

By just copying over the bitcoind and bitcoin-cli binaries you end up with a nice slim image, saving about 30MB. It reduces the image size from 50MB to 20MB, that's less than half the original size!

$ docker images
REPOSITORY                         TAG                 IMAGE ID            CREATED             SIZE
lukechilds/lncm-bitcoind           v0.19.0.1           3a7122158780        3 minutes ago       19.9MB
lncm/bitcoind                      v0.19.0.1           fb1f400f92fd        2 weeks ago         50.8MB

I hope I'm not misunderstanding something and you didn't intentionally want to keep the Berkley DB/Bitcoin Core installation files in this image. I was working under the assumption that this is just supposed to be a super lightweight Docker wrapper for bitcoind.

I've only made the changes to 0.19/Dockerfile for now for you to test. Let me know if you're happy with this change and I'll update the other versions.

meeDamian commented 4 years ago

Interesting. I always blindly assumed that the final binaries depend on this stuff at runtime, but it does seem like they don't indeed 🤔.

$ ldd /opt/bitcoin-0.19.0.1/bin/bitcoin* | grep opt | wc -l
0

I'd rather we didn't discard other binaries produced, namely:

bitcoin-cli
bitcoin-wallet
bitcoin-tx
bitcoind

Also, when you remove the PATH line, does the below still work?

docker run -it --rm --entrypoint=bitcoin-cli lncm/bitcoind:v0.19.0.1 --version
meeDamian commented 4 years ago

Ah, you can also remove stripping of the stuff above that's not being copied in (L115, L125-126).

meeDamian commented 4 years ago

Ah, forget about my PATH question, only now notices you copy them into a different location.

lukechilds commented 4 years ago

I've made the changes requested.

meeDamian commented 4 years ago

Beautiful :)