Dockerのお勉強 - Alpine Linux (2)
OpenRCとやらもちょっと見てみたいけど今日はここまで
OpenRCっていうのはGentooが作っているものらしい
サービスを追加するときなんかに関係しそうな気もするので少し見ておく
OpenRC is a dependency-based init system that maintains compatibility with the system provided init program, normally located in /sbin/init. It does not function as a replacement for the /sbin/init file. OpenRC is 100% compatible with Gentoo init scripts, which means a solution can be found to run the dozens of daemons in the main Gentoo repository. OpenRC, however, is not designed to be exclusively used by Gentoo Linux and can be used on other distributions and BSD systems.
たぶんLinuxの知識がなさすぎてよくわからない
OpenRCは、依存性ベースのinitシステムで、通常は/sbin/initに置かれ、initによって提供されるシステムとの互換性を維持します。
何と何の互換性をとっているのかよくわからない
/sbin/initファイルの置き換えとしては機能しません。
/sbin/initに置かれるのに?
OpenRCはGentooのinitスクリプトと100%互換性を持ちます。つまり、Gentooのメインリポジトリにある多数のデーモンを実行するソリューションが見つかるということです。
/sbin/init一般とは互換性はないけど、GentooではinitスクリプトがOpenRCでも動くように書いてあるから動くよ、ってことかな?
しかし、OpenRCはGentoo Linux専用に使われるよう設計されたものではなく、他のディストリビューションやBSDシステムでも利用することができます。
OpenRCで動くように気を使ってくれれば利用できるよ、ってこと?
ちょっとログインして見てみよう
/sbin # ls -l init
lrwxrwxrwx 1 root root 12 Sep 11 20:23 init -> /bin/busybox
initもBusyBoxであることよ
init.dでも見にいくか
/ # ls
bin dev etc home lib media mnt proc root run sbin srv sys tmp usr var
/ # cd etc
/etc # ls
TZ fstab inittab modules opt profile.d shadow udhcpd.conf
alpine-release group issue modules-load.d os-release protocols shells
apk hostname localtime motd passwd resolv.conf ssl
conf.d hosts logrotate.d mtab periodic securetty sysctl.conf
crontabs init.d modprobe.d network profile services sysctl.d
/etc # cd init.d
/etc/init.d # ls
/etc/init.d #
何もなかった
/etc/inittab
# /etc/inittab
::sysinit:/sbin/openrc sysinit
::sysinit:/sbin/openrc boot
::wait:/sbin/openrc default
# Set up a couple of getty's
tty1::respawn:/sbin/getty 38400 tty1
(snip)
tty6::respawn:/sbin/getty 38400 tty6
# Put a getty on the serial port
#ttyS0::respawn:/sbin/getty -L ttyS0 115200 vt100
# Stuff to do for the 3-finger salute
::ctrlaltdel:/sbin/reboot
# Stuff to do before rebooting
::shutdown:/sbin/openrc shutdown
ちょっと何やってるかよくわからんなー
ランレベルとかない?
コンテナだからそういうのはホストに任せられるのか
だいたい/sbin/openrcなんていうファイルはなさそうなんだけどいいのかな
/sbin/initのことなんだろうか
・・・スルーしてapkためそう
パッケージはAlpine Linux packagesから探すのかな?
pythonで検索してみたら何も出てこない
うーわからん
ちゃんとドキュメント読まないとダメか?
いやまずは先人の知恵にすがろう
これがまとまってる気がした
Alpine Linux入門 -環境構築編-
これはDockerのAlpineイメージの話ではなくて、仮想マシン上で生の(?)Alpine Linuxを
動かしてAlpine Linuxそのものに慣れましょう的な話
実際にはやってませんが、インストール画面を眺めてるだけでも伝わってくる雰囲気みたいなものはあります
Alpine Linux入門 -内部構造とapkでパッケージインストール編-
こちらにはapkの使い方がわりあい詳しく書いてある
使い始めるときにapk update
、
apk search
でパッケージを探してapk add
でパッケージ追加
イメージを小さくするためにはインストール時にしか使わないパッケージを
apk del
で削除しておくことも大事ぽい
試す
/ # apk update
fetch http://dl-cdn.alpinelinux.org/alpine/v3.8/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.8/community/x86_64/APKINDEX.tar.gz
v3.8.1-146-g7276e887a1 [http://dl-cdn.alpinelinux.org/alpine/v3.8/main]
v3.8.1-142-g179c136670 [http://dl-cdn.alpinelinux.org/alpine/v3.8/community]
OK: 9548 distinct packages available
/ # apk search python3
boost-python3-1.66.0-r0
python3-tkinter-3.6.3-r1
python3-idle-3.6.3-r1
:
:
python3-tests-3.6.6-r0
libpeas-python3-1.22.0-r0
/ # apk add python3
(1/11) Installing libbz2 (1.0.6-r6)
(2/11) Installing expat (2.2.5-r0)
:
:
(11/11) Installing python3 (3.6.6-r0)
Executing busybox-1.28.4-r1.trigger
OK: 67 MiB in 24 packages
/ # python3
Python 3.6.6 (default, Aug 24 2018, 05:04:18)
[GCC 6.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> print("Hello, world!")
Hello, world!
>>>
/ # apk del python3
(1/11) Purging python3 (3.6.6-r0)
(2/11) Purging libbz2 (1.0.6-r6)
:
:
(11/11) Purging sqlite-libs (3.24.0-r0)
Executing busybox-1.28.4-r1.trigger
OK: 4 MiB in 13 packages
/ # python3
/bin/sh: python3: not found
あとは必要に応じて調べ直すくらいでいけるかな
apkとだけ叩けば簡単なヘルプは出てくる
/ # apk
apk-tools 2.10.1, compiled for x86_64.
Installing and removing packages:
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
:
:
This apk has coffee making abilities.
apk サブコマンド --help
でサブコマンドの詳細なヘルプ
/ # apk add --help
apk-tools 2.10.1, compiled for x86_64.
usage: apk add [-h|--help] [-p|--root DIR] [-X|--repository REPO] [-q|--quiet] [-v|--verbose] [-i|--interactive]
:
:
This apk has coffee making abilities.
なんかコーヒー作れるよって威張ってくるんですがなんでしょうか
(Docker用途であれば基本的にプロセスをフォアグラウンドで実行するので必要ではありませんが)
なるほどね
これで納得
次回はAlpineの軽量さを活かしたDockerイメージの作り方について書きまする。
次回はなかった模様
残念