A note on a small Docker image container
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
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