Assembly in Docker
| The image | |
| Assemble in a container | |
| Mount your source |
The image
Any image with binutils works: the official alpine image is small and ships nasm and ld. Pull it once and you have an assembler in a clean room:
docker pull alpine
docker run --rm alpine apk add --no-cache nasm binutils
Assemble in a container
Run the assembler inside the container. Mount the current directory so the assembler sees your source and writes the object back to it:
docker run --rm -v "$PWD":/src alpine
sh -c "apk add --no-cache nasm binutils >/dev/null
&& cd /src && nasm -f elf64 -o hello.o hello.asm
&& ld -o hello hello.o"
Mount your source
Keep your sources on the host and treat the container as a tool, like a compiler version pin. The same trick works in CI: pin the image tag, and every build assembles with the exact same toolchain.
Next: ARM assembly
Article author: Arthur Isaev