■docker alpineで/bin/shを使ってみる。
以下の続き。
dockerでHello Worldしてみる。
https://labunix.hateblo.jp/entry/20200908/1599492125
■前回のゴミを削除
$ docker ps -a | awk '$2 ~ /hello-world/{print "docker rm -f "$1 | "sh"}'
90ce255d3b90
d66e4f829335
0cc999eb7e59
3a93386ef7cd
b6be63be1de7
82790f2cdfde
878d411ba706
78e0c25f191d
■json確認用にjqをインストール
$ sudo apt-get install -y jq
$ jq --version
jq-1.5-1-a5b5cbe
■オフィシャルのalpineを検索
$ docker search --filter is-official=true alpine
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
alpine A minimal Docker image based on Alpine Linux… 6750 [OK]
■alpineのイメージをダウンロード
$ docker pull alpine
Using default tag: latest
latest: Pulling from library/alpine
df20fa9351a1: Pull complete
Digest: sha256:185518070891758909c9f839cf4ca393ee977ac378609f700f60a771a2dfe321
Status: Downloaded newer image for alpine:latest
■詳細のJsonからコマンドを確認。
$ docker inspect alpine | jq '.[].Config | .Cmd[]'
"/bin/sh"
■alpineコンテナに対話型に仮想TTYに接続。
$ docker container run -it alpine
/
arch date fdflush kbd_mode mknod ping6 setpriv umount
ash dd fgrep kill mktemp pipe_progress setserial uname
base64 df fsync link more printenv sh usleep
bbconfig dmesg getopt linux32 mount ps sleep watch
busybox dnsdomainname grep linux64 mountpoint pwd stat zcat
cat dumpkmap gunzip ln mpstat reformime stty
chgrp echo gzip login mv rev su
chmod ed hostname ls netstat rm sync
chown egrep ionice lzop nice rmdir tar
conspy false iostat makemime pidof run-parts touch
cp fatattr ipcalc mkdir ping sed true
/
■ログの確認
$ docker container ls -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f09d2c9dc1c8 alpine "/bin/sh" 5 minutes ago Exited (0) 29 seconds ago peaceful_stallman
$ docker logs f09d2c9dc1c8
/
arch date fdflush kbd_mode mknod ping6 setpriv umount
ash dd fgrep kill mktemp pipe_progress setserial uname
base64 df fsync link more printenv sh usleep
bbconfig dmesg getopt linux32 mount ps sleep watch
busybox dnsdomainname grep linux64 mountpoint pwd stat zcat
cat dumpkmap gunzip ln mpstat reformime stty
chgrp echo gzip login mv rev su
chmod ed hostname ls netstat rm sync
chown egrep ionice lzop nice rmdir tar
conspy false iostat makemime pidof run-parts touch
cp fatattr ipcalc mkdir ping sed true
/
■docker container execを使ってコンテナに入ってみる。
$ docker container run -it alpine
/
※別のシェルから。
$ docker container ls
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
02fa7cd2ef04 alpine "/bin/sh" 27 seconds ago Up 25 seconds infallible_yalow
$ docker container exec -it 02fa7cd2ef04 /bin/sh
/
$ docker container ls
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
02fa7cd2ef04 alpine "/bin/sh" About a minute ago Up About a minute infallible_yalow
※元のシェル(alpine)を抜ける。
/
bin dev etc home lib media mnt opt proc root run sbin srv sys tmp usr var
/
$ docker container ls
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
$ docker logs 02fa7cd2ef04
/
bin dev etc home lib media mnt opt proc root run sbin srv sys tmp usr var
/