Small Docker container

A note on a small Docker image container

Contents of scratch

I tried the following to make sure the contents of scratch were completely empty.

$ uname -sm
Darwin x86_64
$ GOOS=linux GOARCH=arm64 go build -o hello hello.go
$ cat > Dockerfile
FROM scratch

COPY hello /hello
ENTRYPOINT ["/hello"]
^D
$ docker image build -t test/hello .

$ docker image ls
REPOSITORY TAG    IMAGE ID     CREATED     SIZE
test/hello latest b5590fa74374 2 hours ago 2.04MB

$ docker run test/hello
Hello, World

$ docker image save -o out.tar test/hello
$ ls -lhn out.tar
-rw-------  1 501  20   2.0M  9 10 18:12 out.tar

$ tar xvf out.tar 
x 53d2a1a74edd0b6d3863682083df76fa417ebe730feecd84a55309fe407f7b0d/
x 53d2a1a74edd0b6d3863682083df76fa417ebe730feecd84a55309fe407f7b0d/VERSION
x 53d2a1a74edd0b6d3863682083df76fa417ebe730feecd84a55309fe407f7b0d/json
x 53d2a1a74edd0b6d3863682083df76fa417ebe730feecd84a55309fe407f7b0d/layer.tar
x b5590fa74374835c813ed2c8490b2997581d3b815d306be739a2be67f6664792.json
x manifest.json
x repositories

$ tar tvf 53d2a1a74edd0b6d3863682083df76fa417ebe730feecd84a55309fe407f7b0d/layer.tar
-rwxr-xr-x  0 0      0     2038890  9 10 16:28 hello

Make a small container from a tar ball

Since it is a container, it will work if you import the chroot environment into tar.

$ mkdir chroot
$ GOOS=linux GOARCH=arm64 go build -o chroot/hello hello.go
$ ls -lRhn chroot
total 4104
-rwxr-xr-x  1 501  20   2.0M  9 10 18:21 hello

$ (cd chroot; tar cf ../image.tar .)
$ ls -lhn image.tar 
-rw-r--r--  1 501  20   2.0M  9 10 18:24 image.tar

$ docker image import image.tar test/import

$ docker image ls test/import
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
test/import         latest              bb6be6e60bb1        19 seconds ago      2.1MB

$ docker run test/import /hello
Hello, World

Worked well

Recommended Posts

Small Docker container
Docker container usage scene
Athrill's Docker container minimization procedure
docker
Introduction to Linux Container / Docker (Part 1)
Run React on a Docker container
Run GUI application on Docker container
Introduction to Linux Container / Docker (Part 2)
Run PureScript on a Docker container
Pass environment variables to docker container
[Docker] Operation up to container creation # 2
docker single container restart for myself
[Linux] Start Apache container with Docker
Build WebRTC Janus with Docker container
About Docker, disguise server and container
docker memo
Docker push to GitHub Container Registry (ghcr.io)
kubernetes + docker
spring × docker
About Docker
Kind @ Mac in Docker and vctl container
Launch docker container on EC2 (personal memorandum)
Run NordVPN on Docker (Windows) Ubuntu container
Docker Intellij
The story of updating SonarQube's Docker Container
Docker basics
MySQL container does not start in Docker
Directly operate mariadb running in Docker container
Docker installation
[Docker] Copy files from docker container to host
About Docker
[Docker] Start the container as soon as possible
Docker memorandum
[Docker] Start container, start bash in container, delete image
Docker container build fails to install php-radis
Introduction to Docker / Kubernetes Practical Container Development
Understand Docker
Docker memorandum
Japanese setting of mysql in Docker container
Run GUI application on Docker container (Japanese input)
How to check the logs in the Docker container
Why use Docker? Docker recommendations for small cis tubes
[Docker] Check the running container and enter there
How to get a heapdump from a Docker container
Extract key phrases using Text Analytics Docker container
Keep docker container running with no resident process running
Build a Kotlin app using OpenJDK's Docker container
Setting to exit from Docker container with VScode
Copy files from docker container to host (docker cp)
I made a Docker container to run Maven
How to update pre-built files in docker container
Send emails using Docker container on Raspberry Pi 3
Edit Docker Container in VSCode multi-stage SSH Vagrant
Build a container for Docker x Laravel phpMyAdmin
Update container image with KUSANAGI Runs on Docker
I tried running Ansible on a Docker container
Docker Container Operations with Docker-Client API for Java
Change the location folder of Docker image & container
How Docker works ~ Implement the container in 60 lines
Try using another Servlet container Jetty with Docker
Docker Container pull has a rate limit enforced