From f55431e897ce62a2f4697a488467e8b7a1bdedcd Mon Sep 17 00:00:00 2001 From: Natanael Copa Date: Wed, 29 Jun 2016 15:48:28 -0700 Subject: [PATCH 1/2] Replace with portable version in C Build a minimal version in C instead of assembly so it easily can be ported to other archs. This statically linked C version builds a binary that is 1472 bytes. fixes #7 --- hello.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 hello.c diff --git a/hello.c b/hello.c new file mode 100644 index 00000000..741b56b1 --- /dev/null +++ b/hello.c @@ -0,0 +1,39 @@ +/* hello.c + +build with: + + gcc -nostartfiles -fno-asynchronous-unwind-tables -Os -static -o hello hello.c + strip -R .comment -s hello + +*/ + +#include + +const char message[] = "\n" +"Hello from Docker.\n" +"This message shows that your installation appears to be working correctly.\n" +"\n" +"To generate this message, Docker took the following steps:\n" +" 1. The Docker client contacted the Docker daemon.\n" +" 2. The Docker daemon pulled the \"hello-world\" image from the Docker Hub.\n" +" 3. The Docker daemon created a new container from that image which runs the\n" +" executable that produces the output you are currently reading.\n" +" 4. The Docker daemon streamed that output to the Docker client, which sent it\n" +" to your terminal.\n" +"\n" +"To try something more ambitious, you can run an Ubuntu container with:\n" +" $ docker run -it ubuntu bash\n" +"\n" +"Share images, automate workflows, and more with a free Docker Hub account:\n" +" https://hub.docker.com\n" +"\n" +"For more examples and ideas, visit:\n" +" https://docs.docker.com/userguide/\n" +"\n"; + +void _start() +{ + write(1, message, sizeof(message)-1); + _exit(0); +} + From 85fd7ab65e079b08019032479a3f306964a28f4d Mon Sep 17 00:00:00 2001 From: Tianon Gravi Date: Wed, 29 Jun 2016 16:30:19 -0700 Subject: [PATCH 2/2] Switch to the C version officially, and make some minor modifications to ensure cross-architecture compatibility is maximized --- Dockerfile.build | 11 ++++- Dockerfile.template | 3 -- Makefile | 21 ++++----- hello-seattle/greeting.txt | 1 + hello-seattle/hello | Bin 987 -> 1864 bytes hello-world/greeting.txt | 1 + hello-world/hello | Bin 967 -> 1848 bytes hello.asm | 93 ------------------------------------- hello.c | 68 ++++++++++++++------------- hola-mundo/greeting.txt | 1 + hola-mundo/hello | Bin 988 -> 1864 bytes update.sh | 14 +++--- 12 files changed, 64 insertions(+), 149 deletions(-) delete mode 100644 Dockerfile.template create mode 100644 hello-seattle/greeting.txt create mode 100644 hello-world/greeting.txt delete mode 100644 hello.asm create mode 100644 hola-mundo/greeting.txt diff --git a/Dockerfile.build b/Dockerfile.build index 26a16396..ed3de7ce 100644 --- a/Dockerfile.build +++ b/Dockerfile.build @@ -1,10 +1,17 @@ +# explicitly use Debian for maximum cross-architecture compatibility FROM debian:jessie -RUN apt-get update && apt-get install -y make nasm && rm -rf /var/lib/apt/lists/* +RUN apt-get update && apt-get install -y --no-install-recommends \ + gcc \ + libc6-dev \ + make \ + && rm -rf /var/lib/apt/lists/* WORKDIR /usr/src/hello COPY . . -RUN make clean all test +RUN set -x \ + && make clean all test \ + && ls -l */hello CMD ["./hello-world/hello"] diff --git a/Dockerfile.template b/Dockerfile.template deleted file mode 100644 index d4ff707c..00000000 --- a/Dockerfile.template +++ /dev/null @@ -1,3 +0,0 @@ -FROM scratch -COPY hello / -CMD ["/hello"] diff --git a/Makefile b/Makefile index fe91e7ce..d0b0b633 100644 --- a/Makefile +++ b/Makefile @@ -1,24 +1,21 @@ -IMAGES := \ - hello-world \ - hola-mundo \ - hello-seattle +C_TARGETS := $(addsuffix hello, $(wildcard */)) -ASM_TARGETS := $(addsuffix /hello, $(IMAGES)) +CC := gcc +CFLAGS := -static -Os -nostartfiles -fno-asynchronous-unwind-tables .PHONY: all -all: $(ASM_TARGETS) +all: $(C_TARGETS) -$(ASM_TARGETS): hello.asm - mkdir -p '$(dir $@)' - nasm -o '$@' -DDOCKER_IMAGE="'$$(dirname '$@')'" '$<' - chmod +x '$@' +$(C_TARGETS): hello.c + $(CC) $(CFLAGS) -o '$@' -D DOCKER_IMAGE='"$(@D)"' -D DOCKER_GREETING="\"$$(cat '$(@D)/greeting.txt')\"" '$<' + strip -R .comment -s '$@' .PHONY: clean clean: - -rm -vrf $(addsuffix /, $(IMAGES)) + -rm -vrf $(C_TARGETS) .PHONY: test -test: $(ASM_TARGETS) +test: $(C_TARGETS) @for b in $^; do \ ( set -x && "./$$b" ); \ ( set -x && "./$$b" | grep -q '"'"$$(dirname "$$b")"'"' ); \ diff --git a/hello-seattle/greeting.txt b/hello-seattle/greeting.txt new file mode 100644 index 00000000..a2a137d5 --- /dev/null +++ b/hello-seattle/greeting.txt @@ -0,0 +1 @@ +Hello from DockerCon 2016 (Seattle)! diff --git a/hello-seattle/hello b/hello-seattle/hello index dd34b0019e76d7d6201e6513d280e79fe56f11fd..f7ef94c4037b488f9c5a809ba8507f90d525fa9d 100755 GIT binary patch delta 937 zcmZuvJ4*vW5S}wnP?CTaf}#fE3v@9kVv*n#f+r*r1q*F7;o<{)k(>}jNTG#?Am$fX zSy|Z#T9}|su(J`tTG2+tLM?=IX0sd4;K$8#XKv@QkDjvcsJT0#s6eQ2fPEJ?Ia6T- zoOt2^cVRS`*Tj*O03AHciJYiI;U-FzD^i9kZjh2<2_7WUtN#lupoNgKV(}PMeNus` zCqs7^f{ld%XU&%n*m9ascOZ>V&cNO2><}A#PVMN?lMmnA`C;KLDnhwPT$ZrvE9#&~ z>>`4h;nEBJV=nwzjGzpcUTFgU_A#v4{MO7b&Aivl+qiihH_NeuSjgM!cWF`O-Lm|< z^%#1y$o%bls9?g^gKj!Ie=N(=cFWey*>S{?rvtiyplnZrk_#v;4Ib|imO%biqyv!(SdmfBib)%#a;U`9G;0LyIXNh1j?y*$5| zNqX1Pc#z6w|D9#cXwk%asVmxB9lw%xu5wN8J|z57(0=V`Lxbk)7Eby6668c|Rz#Km z>5%3{7f`G$fYwGRi62C9Z+5751NA;6dp@{CgnZmJ@m`xfLHaNfIUTY!@ml38mTrnA V)Y^2p0|(wC6X+LvE`xIh!-fg|?idYsqVntkV*v=8ogGS4*_`|@3AYcUa+eO|rd4GX# zIFt~9GoEP$i{DS|t$&OiDDZaYF#H!+QIjo8tEGvnRGb z|L2-#+?{tFm_S znh=BepM&|s!ThJe{Kp&f?{CZ>?0&VovATAC@MiCLu~@tHB#`$<@!G{N@B;k9pVRsB z3x6*bi@~i2i~G?)6@{iztxLM5lLJ*hAMIzkp;8$m$BIm*r-p1MEgkBnro1v%7KOCA zu1HQMO4c~mG*mRz^+8^ZDbaPU5?dU`QM9jVtSVJYt6=1j-A(Tes`>yYibfiNOj+Mp zH8HP8v>nqv4%)CNDRNa=7_Y2MtV*4dKTD-5brnbS$|;prOp~T4JpNL~>24v?BE3X; z$r-xbIRbBN&xN)yBo8~3Y5r-QzNjO!=|#3a8Fzz zrn$|~xeZF)U2?ds+)~p5htgzG^nS)kx=O*MY^*N%dhqob;R>*2F|i7un)x~^LbY9`A`fjYCzJXI3rKgmtrRfeMJX!lh$MmGJ% zsCwK$ryoV`rX7a8D*<(IL(ggndycNCip z-NS_taiy(_$5j&#o4iQ3@>IlD&8&!VMWmG?R@q0R8hwU*XpFb~{}_)2o`p-^OqiQt zo^G5m&vUFx&tb#!Da^z$@Ap^;nzZcXc`A2E**-&qf1Y|wM_&JBjJ+=HbT@e4#OmrF xFSm$eALyx}3hXLYmtMn$W#>X-e*TC5LJ$X?vwQY^CPW7f`aGw*U;emMXD delta 103 zcmdnNcbt8K1ZM?<0|N*+O#CR!?Z9BczzF6tOte?DKh6wc!)OKu1+c&lkedA +#include -build with: +#ifndef DOCKER_IMAGE + #define DOCKER_IMAGE "hello-world" +#endif - gcc -nostartfiles -fno-asynchronous-unwind-tables -Os -static -o hello hello.c - strip -R .comment -s hello +#ifndef DOCKER_GREETING + #define DOCKER_GREETING "Hello from Docker!" +#endif -*/ +const char message[] = + "\n" + DOCKER_GREETING "\n" + "This message shows that your installation appears to be working correctly.\n" + "\n" + "To generate this message, Docker took the following steps:\n" + " 1. The Docker client contacted the Docker daemon.\n" + " 2. The Docker daemon pulled the \"" DOCKER_IMAGE "\" image from the Docker Hub.\n" + " 3. The Docker daemon created a new container from that image which runs the\n" + " executable that produces the output you are currently reading.\n" + " 4. The Docker daemon streamed that output to the Docker client, which sent it\n" + " to your terminal.\n" + "\n" + "To try something more ambitious, you can run an Ubuntu container with:\n" + " $ docker run -it ubuntu bash\n" + "\n" + "Share images, automate workflows, and more with a free Docker Hub account:\n" + " https://hub.docker.com\n" + "\n" + "For more examples and ideas, visit:\n" + " https://docs.docker.com/engine/userguide/\n" + "\n"; -#include +void _start() { + //write(1, message, sizeof(message) - 1); + syscall(SYS_write, 1, message, sizeof(message) - 1); -const char message[] = "\n" -"Hello from Docker.\n" -"This message shows that your installation appears to be working correctly.\n" -"\n" -"To generate this message, Docker took the following steps:\n" -" 1. The Docker client contacted the Docker daemon.\n" -" 2. The Docker daemon pulled the \"hello-world\" image from the Docker Hub.\n" -" 3. The Docker daemon created a new container from that image which runs the\n" -" executable that produces the output you are currently reading.\n" -" 4. The Docker daemon streamed that output to the Docker client, which sent it\n" -" to your terminal.\n" -"\n" -"To try something more ambitious, you can run an Ubuntu container with:\n" -" $ docker run -it ubuntu bash\n" -"\n" -"Share images, automate workflows, and more with a free Docker Hub account:\n" -" https://hub.docker.com\n" -"\n" -"For more examples and ideas, visit:\n" -" https://docs.docker.com/userguide/\n" -"\n"; - -void _start() -{ - write(1, message, sizeof(message)-1); - _exit(0); + //_exit(0); + syscall(SYS_exit, 0); } - diff --git a/hola-mundo/greeting.txt b/hola-mundo/greeting.txt new file mode 100644 index 00000000..e9740fd6 --- /dev/null +++ b/hola-mundo/greeting.txt @@ -0,0 +1 @@ +¡Hola de DockerCon EU 2015 (Barcelona)! diff --git a/hola-mundo/hello b/hola-mundo/hello index 0d8f5df74186996e1df151073dedb087b695a34d..4d6496d3d4d15543de37dc2cb01a3636ff002674 100755 GIT binary patch delta 936 zcmZuvJ4*vW5S}xS3n(U_pr9Cq_(Tr_A{Iuk5IjXC3KrUE!d+C*D9HtaAStx)urMjC zZTtfkB3fwBCinxy!dB4E#z!HXGn?IT20w0gX1<-d-I>{Exm2HT?v6?-5XvjSp@+F_ zQDFq!xFdtNFy4{V_?FNB?JUfVD@nV=T+}KvgbtNy5Sn5MG78z1{{>djLkL~=SPYu= z!hrb~Q}-4+8VZB%sxKFCAxmzIeP$WSUNn_s)KjJd~;EbrElU zLlxZ8auvbMaPgJ?u^j%q9Yq~3zEKDK!3n&x^{rW7n)Rqz53|YDzn7sL!1|i#_L2II@De-C&lZF5{cL; ztIGPPLTVQsK(XQiG&Mqz|6mNq=7j2W(C$ZZ=7Wbvh__u8?{oN5WDlbd=@O;!$0{DN YpedG6?bG2dY /dev/null + +rm -rf */hello +docker run --rm hello-world:build sh -c 'tar --create */hello' | tar --extract --wildcards '*/hello' + +for h in */hello; do + d="$(dirname "$h")" + "$h" > /dev/null docker build -t hello-world:"test-$d" "$d" docker run --rm hello-world:"test-$d" done