LoginSignup
0
0

More than 1 year has passed since last update.

Docker Scratch

Last updated at Posted at 2019-05-29

scratchのDocker

前の記事(Liberty on Docker)では、「FROM scratch」からDockerfileを書き、それに「alpine-minirootfs」を追加して始めました。
では、「FROM scratch」の状態でどんな感じなんでしょう。

まず、busyboxを用意します。以下の内容としました。

bash-5.0# tar tvf busybox-1.33.1.tar.xz
rwxr-xr-x root/root    829000 2021-06-29 16:21:40 bin/busybox
-rwxr-xr-x root/root    604744 2021-05-09 14:35:27 lib/ld-musl-x86_64.so.1bash-5.0#

これを用いて、Dockerfileを作ります。

Dockerfile
FROM scratch
ADD busybox-1.33.1.tar.xz /
CMD ["/bin/busybox","sh"]

ビルドします。

C:\Docker\scratch>docker build -t alpine:scratch --progress plain .
#1 [internal] load build definition from D.txt
#1 sha256:8a8527aac156990ba8d06fd7c7d20dd2f5393805d6643fdd9209540e1fcd00dd
#1 transferring dockerfile: 26B done
#1 DONE 0.0s

#2 [internal] load .dockerignore
#2 sha256:097436c38e23b81817b37e506f2b80522bc4acbc10b656de0e06b2fb80743ff6
#2 transferring context: 2B done
#2 DONE 0.0s

#3 [internal] load build context
#3 sha256:783171eb8e6d71bea434389157ece90d9bfce5e67b83cb7bdd7e8b2f5e824465
#3 transferring context: 44B done
#3 DONE 0.0s

#4 [1/1] ADD busybox-1.33.1.tar.xz /
#4 sha256:28496066e1d6d3a748a161cb424c518dbb6849c160dda8a44b1f0472280f7cf6
#4 CACHED

#5 exporting to image
#5 sha256:e8c613e07b0b7ff33893b694f7759a10d42e180f2b4dc349fb57dc6b71dcab00
#5 exporting layers done
#5 writing image sha256:3738a4ead8ad904a691fac14eb7775eeb8a3017f0a6eadbf9305a5a53a51ece2 done
#5 naming to docker.io/library/alpine:scratch done
#5 DONE 0.0s

Use 'docker scan' to run Snyk tests against images to find vulnerabilities and learn how to fix them

では、動かしてsys/proc以外をリストしてみましょう。

C:\Docker\scratch>docker run -it --rm alpine:scratch
/ # /bin/busybox ls -l bin dev etc lib
bin:
total 812
-rwxr-xr-x    1 0        0           829000 Jun 29 16:21 busybox

dev:
total 0
crw--w----    1 0        5         136,   0 Sep 21 00:39 console
lrwxrwxrwx    1 0        0               11 Sep 21 00:39 core -> /proc/kcore
lrwxrwxrwx    1 0        0               13 Sep 21 00:39 fd -> /proc/self/fd
crw-rw-rw-    1 0        0           1,   7 Sep 21 00:39 full
drwxrwxrwt    2 0        0               40 Sep 21 00:39 mqueue
crw-rw-rw-    1 0        0           1,   3 Sep 21 00:39 null
lrwxrwxrwx    1 0        0                8 Sep 21 00:39 ptmx -> pts/ptmx
drwxr-xr-x    2 0        0                0 Sep 21 00:39 pts
crw-rw-rw-    1 0        0           1,   8 Sep 21 00:39 random
drwxrwxrwt    2 0        0               40 Sep 21 00:39 shm
lrwxrwxrwx    1 0        0               15 Sep 21 00:39 stderr -> /proc/self/fd/2
lrwxrwxrwx    1 0        0               15 Sep 21 00:39 stdin -> /proc/self/fd/0
lrwxrwxrwx    1 0        0               15 Sep 21 00:39 stdout -> /proc/self/fd/1
crw-rw-rw-    1 0        0           5,   0 Sep 21 00:39 tty
crw-rw-rw-    1 0        0           1,   9 Sep 21 00:39 urandom
crw-rw-rw-    1 0        0           1,   5 Sep 21 00:39 zero

etc:
total 12
-rw-r--r--    1 0        0               13 Sep 21 00:39 hostname
-rw-r--r--    1 0        0              174 Sep 21 00:39 hosts
lrwxrwxrwx    1 0        0               12 Sep 21 00:39 mtab -> /proc/mounts
-rw-r--r--    1 0        0               97 Sep 21 00:39 resolv.conf

lib:
total 592
-rwxr-xr-x    1 0        0           604744 May  9 14:35 ld-musl-x86_64.so.1
/ #

最低限のデバイスのみですね。
busybox:muslのmusl/Dockerfileも見てみます。

Dockerfile
FROM scratch
ADD busybox.tar.xz /
CMD ["sh"]

上に書いたのと同じようなことをやっていますね。

ちなみにalpinelinuxのDockerファイルは以下です。

Dockerfile
FROM scratch
ADD alpine-minirootfs-3.15.4-x86_64.tar.gz /
CMD ["/bin/sh"]

minirootfsを展開しているだけですね。busyboxはv1.34.1でした。今まで、scrachでrootfsをaddしていたものを変更しようかな。でもCMDは場合によっていらないし。。

##変更履歴
(2019/5/30)shのリンクを削除し、busyboxを使用する変更
(2019/8/27)アーカイブの圧縮をxzに変更。使用するベースのbusyboxを1.31.0とし、情報を再取得。dockerイメージのリストアップを削除。
(2020/5/23)busyboxを1.31.1に変更。
(2021/9/21)busyboxを1.33.1に変更。
(2022/3/26)alpine linuxのbusyboxの記述を追加。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0