Skip to content

Instantly share code, notes, and snippets.

@tonymet
Last active May 7, 2019 22:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tonymet/a80595400b8481e8a0274d63c290ceec to your computer and use it in GitHub Desktop.
Save tonymet/a80595400b8481e8a0274d63c290ceec to your computer and use it in GitHub Desktop.
ultra-tiny 1kB docker images

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
_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
int 80h ; call the kernel
; Terminate program
mov eax,1 ; 'exit' system call
mov ebx,0 ; exit with error code 0
int 80h ; call the kernel
hello.o: hello.asm
nasm -f elf64 $< -o $@
hello: hello.o
ld $< -o $@
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment