$ docker images |grep tiny-hello
tiny-hello latest 21d5b79018bb 2 minutes ago 952B
-
-
Save tonymet/a80595400b8481e8a0274d63c290ceec to your computer and use it in GitHub Desktop.
ultra-tiny 1kB docker images
This file contains hidden or 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
| *.o | |
| hello | |
| a.out | |
| hex | |
This file contains hidden or 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
| FROM alpine:latest as builder | |
| WORKDIR /build | |
| RUN apk update && \ | |
| apk add nasm make binutils | |
| COPY . ./ | |
| RUN make hello | |
| FROM scratch | |
| WORKDIR / | |
| COPY --from=builder /build/hello . | |
| CMD ["/hello"] |
This file contains hidden or 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
| ; Define variables in the data section | |
| SECTION .DATA | |
| hello: db 'Hello world!',10 | |
| helloLen: equ $-hello | |
| ; Code goes in the text section | |
| SECTION .TEXT | |
| GLOBAL _start | |
| kernel: | |
| int 80h ; Call kernel | |
| ret | |
| _start: | |
| mov eax,4 ; 'write' system call = 4 | |
| mov ebx,1 ; file descriptor 1 = STDOUT | |
| mov ecx,hello ; string to write | |
| mov edx,helloLen ; length of string to write | |
| call kernel ; call the kernel | |
| ; Terminate program | |
| mov eax,1 ; 'exit' system call | |
| mov ebx,0 ; exit with error code 0 | |
| call kernel ; call the kernel |
This file contains hidden or 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
| %include 'system.inc' | |
| section .data | |
| hex db '0123456789ABCDEF' | |
| buffer db 0, 0, ' ' | |
| section .text | |
| global _start | |
| _start: | |
| ; read a byte from stdin | |
| push dword 1 | |
| push dword buffer | |
| push dword stdin | |
| sys.read | |
| add esp, byte 12 | |
| or eax, eax | |
| je .done | |
| ; convert it to hex | |
| movzx eax, byte [buffer] | |
| mov edx, eax | |
| shr dl, 4 | |
| mov dl, [hex+edx] | |
| mov [buffer], dl | |
| and al, 0Fh | |
| mov al, [hex+eax] | |
| mov [buffer+1], al | |
| ; print it | |
| push dword 3 | |
| push dword buffer | |
| push dword stdout | |
| sys.write | |
| add esp, byte 12 | |
| jmp short _start | |
| .done: | |
| push dword 0 | |
| sys.exit |
This file contains hidden or 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
| hello.o: hello.asm | |
| nasm -f elf64 $< -o $@ | |
| hello: hello.o | |
| ld $< -o $@ |
This file contains hidden or 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
| %define stdin 0 | |
| %define stdout 1 | |
| %define stderr 2 | |
| %define SYS_nosys 0 | |
| %define SYS_exit 1 | |
| %define SYS_fork 2 | |
| %define SYS_read 3 | |
| %define SYS_write 4 | |
| ; [etc...] | |
| section .text | |
| align 4 | |
| access.the.bsd.kernel: | |
| int 80h | |
| ret | |
| %macro system 1 | |
| mov eax, %1 | |
| call access.the.bsd.kernel | |
| %endmacro | |
| %macro sys.exit 0 | |
| system SYS_exit | |
| %endmacro | |
| %macro sys.fork 0 | |
| system SYS_fork | |
| %endmacro | |
| %macro sys.read 0 | |
| system SYS_read | |
| %endmacro | |
| %macro sys.write 0 | |
| system SYS_write | |
| %endmacro | |
| ; [etc...] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment