Small. Simple. Secure. のAlpine Linuxのdockerイメージを使う
小さいdockerのイメージが欲しい
dockerをポチポチ触ってみているんですが、imageが大きくなりがちで普段から潤沢とはいえない容量のマシンも使うので少しハラハラしながら使ってました。
しかしあくまでコンテナな訳だしなんとか小さいimageないのかなって見てたらAlpine Linuxのimageがいい具合っぽいということを知りました。
キャッチフレーズは"Small. Simple. Secure."らしい。 Docker Hubにもalpineのイメージがある。 しかもサイズが2MB!
Alpine Linuxはbusyboxという組み込み向けのLinux Distributionが元になっている。
busyboxはパッケージマネジメント機能もないんだが、Alpine Linuxはapk
というコマンドがあってパッケージマネジメント機能も提供してくれてる。
というわけで、僕のようなゆるいエンジニアには優しい作りなのもうれしい。
いい具合に優しさがある。
Rubyのimageでも最近のバージョンのものはalpine版があってimageのサイズが30数MBくらいになってるも最高だ。
すごい簡単に使ってみる
docker run -it alpine /bin/ash
alpineはデフォルトではbashがなくてashを使ってるのでashを使います。 機能はbashやzshに比べると少ないということだけど、まあdockerで使うくらいだったらそんなにシェルの機能は必要なさそうだし気にしない
ごくごく基本的なcat
, cp
, ls
などのコマンドは入ってるけどvi
などは入っていない。
せっかくapk
があるんだし入れてみよう。
まずはapk
と叩いてみて出来ることを確認。
/ # apk apk-tools 2.6.5, compiled for x86_64. usage: apk COMMAND [-h|--help] [-p|--root DIR] [-X|--repository REPO] [-q|--quiet] [-v|--verbose] [-i|--interactive] [-V|--version] [-f|--force] [-U|--update-cache] [--progress] [--progress-fd FD] [--no-progress] [--purge] [--allow-untrusted] [--wait TIME] [--keys-dir KEYSDIR] [--repositories-file REPOFILE] [--no-network] [--no-cache] [--arch ARCH] [--print-arch] [ARGS]... The following commands are available: add Add PACKAGEs to 'world' and install (or upgrade) them, while ensuring that all dependencies are met del Remove PACKAGEs from 'world' and uninstall them fix Repair package or upgrade it without modifying main dependencies update Update repository indexes from all remote repositories info Give detailed information about PACKAGEs or repositores search Search package by PATTERNs or by indexed dependencies upgrade Upgrade currently installed packages to match repositories cache Download missing PACKAGEs to cache and/or delete unneeded files from cache version Compare package versions (in installed database vs. available) or do tests on literal version strings index Create repository index file from FILEs fetch Download PACKAGEs from global repositories to a local directory audit Audit the directories for changes verify Verify package integrity and signature dot Generate graphviz graphs policy Show repository policy for packages stats Show statistics about repositories and installations Global options: -h, --help Show generic help or applet specific help -p, --root DIR Install packages to DIR -X, --repository REPO Use packages from REPO -q, --quiet Print less information -v, --verbose Print more information (can be doubled) -i, --interactive Ask confirmation for certain operations -V, --version Print program version and exit -f, --force Do what was asked even if it looks dangerous -U, --update-cache Update the repository cache --progress Show a progress bar --progress-fd FD Write progress to fd --no-progress Disable progress bar even for TTYs --purge Delete also modified configuration files (pkg removal) and uninstalled packages from cache (cache clean) --allow-untrusted Install packages with untrusted signature or no signature --wait TIME Wait for TIME seconds to get an exclusive repository lock before failing --keys-dir KEYSDIR Override directory of trusted keys --repositories-file REPOFILE Override repositories file --no-network Do not use network (cache is still used) --no-cache Read uncached index from network --arch ARCH Use architecture with --root --print-arch Print default arch and exit This apk has coffee making abilities.
どうやらapk add
を使うと良さそう。
/ # apk add vim WARNING: Ignoring APKINDEX.5a59b88b.tar.gz: No such file or directory WARNING: Ignoring APKINDEX.7c1f02d6.tar.gz: No such file or directory ERROR: unsatisfiable constraints: vim (missing): required by: world[vim]
ん?もしやupdateが必要か。
/ # apk update fetch http://dl-cdn.alpinelinux.org/alpine/v3.3/main/x86_64/APKINDEX.tar.gz fetch http://dl-cdn.alpinelinux.org/alpine/v3.3/community/x86_64/APKINDEX.tar.gz v3.3.3-122-gcf13b9e [http://dl-cdn.alpinelinux.org/alpine/v3.3/main] v3.3.3-74-g713311c [http://dl-cdn.alpinelinux.org/alpine/v3.3/community] OK: 5859 distinct packages available
お、packagesの情報を持ってきたぽい。 再チャレンジ
/ # apk add vim (1/5) Installing lua5.2-libs (5.2.4-r2) (2/5) Installing ncurses-terminfo-base (6.0-r6) (3/5) Installing ncurses-terminfo (6.0-r6) (4/5) Installing ncurses-libs (6.0-r6) (5/5) Installing vim (7.4.943-r3) Executing busybox-1.24.1-r7.trigger OK: 36 MiB in 16 packages
これでvim
が動かせるように!
ash
が気に食わない場合はzsh
もあるし、mysql-dev
やcurl
など各種開発時に必要になりがちなpackageもあるので困ることも少なそう。
simple, smallなのはとても伝わってきた。 (・∀・)イイネ!!
secureの部分はどこを見たら分かるんだろう (・・?
- 作者: Adrian Mouat,Sky株式会社玉川竜司
- 出版社/メーカー: オライリージャパン
- 発売日: 2016/08/17
- メディア: 単行本(ソフトカバー)
- この商品を含むブログを見る