Skip to content

Instantly share code, notes, and snippets.

@tonymet
Last active August 4, 2025 20:31
Show Gist options
  • Select an option

  • Save tonymet/a80595400b8481e8a0274d63c290ceec to your computer and use it in GitHub Desktop.

Select an option

Save tonymet/a80595400b8481e8a0274d63c290ceec to your computer and use it in GitHub Desktop.
ultra-tiny 1kB docker images
*.o
hello
a.out
hex

Ultra-tiny 1kB Docker Image

$ docker images |grep tiny-hello
tiny-hello                                    latest                21d5b79018bb        2 minutes ago       952B
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"]
; 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
%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
hello.o: hello.asm
nasm -f elf64 $< -o $@
hello: hello.o
ld $< -o $@
%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