-
Notifications
You must be signed in to change notification settings - Fork 8.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[BUILD] Minimize docker container sizes
We use two techniques: 1) the use of a minimal docker base (FROM scratch + busybox) 2) the use of a static binary ... to create a minimally sized image for 'peer' and 'orderer' Before this patch, these containers are approximately 1.4GB. After this patch, they are about 20MB-24MB. It isn't strictly necessary to include busybox. The main benefit is achieved simply by eliminating external dependencies in the golang binary using -static and then getting rid of all the bloat in the baseimage via "FROM scratch". However, in this mode the image is pathologically bare-boned. For instance, the image has to be launched using the exec-form '["peer", "node", "start"]' since there is no shell interpreter available to do the more natural "CMD peer node start". Further, any "docker exec" style debugging would be impossible. It is often helpful to jump into a container and poke around with tools like ifconfig, ping, netstat, etc. Enter busybox: We can create a basic unix environment with only a 5MB payload. This is impressive and is easily worth its weight in the image. However, the challenge isn't really justifying the utility of having busybox over saving 5MB as much as it is about how we will get it into the image. If the world were a monochrome x86_64, we could simply s/FROM scratch/FROM busybox and be done. However, we have to consider other multi $arch. To support this, we forgo the temptation to use FROM busybox and build busybox from source. On my 2011 Macbook Pro, this adds about 5 minutes to the build, at least on the first build. Subsequent builds utilize the cache in ./build and thus are no-ops. This is _just_ fast enough that I am not embarrassed to propose it for consideration. However, if this is perceived as a problem we do have alternatives. For instance, we could start distributing a multi-$arch busybox base (hyperledger/fabric-busybox:$arch), TBD. Change-Id: I4ed20a429c2cc2e72fd602b45c5c8dd5548bc995 Signed-off-by: Greg Haskins <gregory.haskins@gmail.com>
- Loading branch information
Showing
5 changed files
with
51 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
BUSYBOX_VER=1.25.1 | ||
BUSYBOX_URL=https://www.busybox.net/downloads/busybox-$(BUSYBOX_VER).tar.bz2 | ||
|
||
OBJDIR=build/busybox-$(BUSYBOX_VER) | ||
|
||
all: $(OBJDIR)/busybox | ||
|
||
install: $(BINDIR)/busybox | ||
|
||
$(BINDIR)/busybox: $(OBJDIR)/busybox | ||
mkdir -p $(@D) | ||
cp $< $@ | ||
|
||
$(OBJDIR)/.source: | ||
mkdir -p $(@D) | ||
curl -L $(BUSYBOX_URL) | (cd $(@D); tar --strip-components=1 -jx) | ||
touch $@ | ||
|
||
$(OBJDIR)/.config: $(OBJDIR)/.source | ||
make -C $(@D) defconfig | ||
|
||
$(OBJDIR)/busybox: Makefile $(OBJDIR)/.config | ||
make -C $(@D) -l 2.5 -j all LDFLAGS=-static | ||
|
||
clean: | ||
-rm -rf $(OBJDIR) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
FROM scratch | ||
COPY payload/busybox /bin/busybox | ||
RUN ["/bin/busybox", "mkdir", "-p", "/usr/bin", "/sbin", "/usr/sbin"] | ||
RUN ["/bin/busybox", "--install"] | ||
RUN mkdir -p /usr/local/bin | ||
ENV PATH=$PATH:/usr/local/bin |