2020/11/09
今回できたこと
既存のDockerイメージから新規のイメージを作成する(手動でapt installを使った環境構築)。
未解決
元々のhttpdイメージは、runで起動した時にhttpdが起動していた。
commitで更新したイメージは、runで起動した時に/bin/bashが動く。
httpd(,sshdも)の起動設定をどうするべきかが良くわからない。
げんざいの~/.bashrcに記述する方法は、無理矢理すぎる。
お約束
参考文献
Linuxエミュレータ(Linuxlator)とjailを使い、Linux版のDockerを動かす。
既存のDockerイメージから新規のイメージを作成する
2020/11/06の作業で、Dockerコンテナを終了した時に、Dockerコンテナの状態が初期化されるとということがわかったが、いくつかの資料を調べると、更新されたイメージを保存する方法があることがわかった。 はじめに、httpdイメージを取得して、その動作を確認する。
code:shell
$ sudo docker pull httpd
(snip)
$ sudo docker images |grep http
httpd latest af8a8b04781c 3 weeks ago 120MB
$ sudo docker run httpd
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 172.17.0.2. Set the 'ServerName' directive globally to suppress this message
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 172.17.0.2. Set the 'ServerName' directive globally to suppress this message
Dockerホスト側から、httpdにアクセスして、初期ページIt works!が返されることを確認する。
code:shell
$ sudo docker ps|grep httpd
e44c2ef50ddc httpd "httpd-foreground" 2 minutes ago Up 2 minutes 80/tcp gifted_dubinsky
$ telnet 172.17.0.2 80
Trying 172.17.0.2...
Connected to 172.17.0.2.
Escape character is '^]'.
GET /index.html
<html><body><h1>It works!</h1></body></html>
Connection closed by foreign host.
httpdイメージで、/bin/bashを動かし、システムの更新とWebpage/index.htmlの更新を行う。
code:shell
$ sudo docker run -it httpd /bin/bash
root@a8eeaea4c70b:/usr/local/apache2# apt update
(snip)
root@a8eeaea4c70b:/usr/local/apache2# apt upgrade
(snip)
The following packages will be upgraded:
libldap-2.4-2 libldap-common tzdata
3 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Need to get 555 kB of archives.
After this operation, 3072 B of additional disk space will be used.
Do you want to continue? Y/n y (snip)
root@a8eeaea4c70b:/usr/local/apache2# cat htdocs/index.html
<html><body><h1>It works!</h1></body></html>
rroot@a8eeaea4c70b:/usr/local/apache2# echo "MUTOH's httpd" > htdocs/index.html
現状では、httpdは動かず、/bin/bashだけが動いているので、httpdを起動しようとするが、以下のエラーが出て起動するがまともに動作しない。
code:shell
root@a8eeaea4c70b:/usr/local/apache2# httpd
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 172.17.0.2. Set the 'ServerName' directive globally to suppress this message
httpdの設定を修正する。
code:httpd.conf.diff
root@a8eeaea4c70b:/usr/local/apache2# diff -u /usr/local/apache2/conf/httpd.conf{.20201109,}
--- conf/httpd.conf.20201109 2020-11-09 02:16:49.528261105 +0000
+++ conf/httpd.conf 2020-11-09 02:17:48.790460064 +0000
@@ -239,6 +239,7 @@
# If your host doesn't have a registered DNS name, enter its IP address here.
#
+ServerName docker-httpd.610t.org:80
#
# Deny access to the entirety of your server's filesystem. You must
httpdを起動すると、Dockerホストから以下のように更新した/index.htmlが取得できている。
code:shell
root@a8eeaea4c70b:/usr/local/apache2# httpd
root@a8eeaea4c70b:/usr/local/apache2# ps agxuw
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.0 3368 2692 pts/0 Ss 02:03 0:00 /bin/bash
root 775 0.0 0.0 6956 3368 ? Ss 02:25 0:00 httpd
daemon 776 0.0 0.0 235648 2648 ? Sl 02:25 0:00 httpd
daemon 777 0.0 0.0 235648 2648 ? Sl 02:25 0:00 httpd
daemon 780 0.0 0.0 235648 2648 ? Sl 02:25 0:00 httpd
root 860 0.0 0.0 5088 2156 pts/0 R+ 02:25 0:00 ps agxuw
code:shell
$ telnet 172.17.0.2 80
Trying 172.17.0.2...
Connected to 172.17.0.2.
Escape character is '^]'.
GET /index.html
MUTOH's httpd
Connection closed by foreign host.
新しいDockerイメージmy_httpdを作成。
code:shell
$ sudo docker commit a8eeaea4c70b my_httpd
sha256:b52faa97791a2e8475ed2e57afe94cfaea0533c3569ec43bf03fd3da30e71822
$ sudo docker images|grep httpd
my_httpd latest b52faa97791a 27 seconds ago 174MB
httpd latest af8a8b04781c 3 weeks ago 120MB
httpdが動いた状態で、新コンテナイメージを保存したが、Dockerを起動してみてもhttpdは動いていない。
code:shell
$ sudo docker run -it my_httpd
root@fb1ad86b257d:/usr/local/apache2# ps agxuw
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.5 0.0 3368 2252 pts/0 Ss 03:07 0:00 /bin/bash
root 7 0.0 0.0 5088 2204 pts/0 R+ 03:07 0:00 ps agxuw
とりあえず、無理やりsshdとhttpdを動かすために、~root/.bashrcに起動設定を追加する。
この記述では、/bin/bashが起動されるたびにsshdとhttpdを起動しようとするため、もう少しまともな設定に変更する必要がある。
code:~root/.bashrc.diff
# diff -u ~/.bashrc{.20201109,}
--- /root/.bashrc.20201109 2020-11-09 03:18:30.000000000 +0000
+++ /root/.bashrc 2020-11-09 03:41:49.000000000 +0000
@@ -16,3 +16,5 @@
# alias rm='rm -i'
# alias cp='cp -i'
# alias mv='mv -i'
+/etc/init.d/ssh start
+/usr/local/apache2/bin/httpd &
新たなイメージmy_httpd2を作成し、起動する。
code:shell
$ sudo docker commit fb1ad86b257d my_httpd2
sha256:7dd1f7c206bbdc17eebd195762928a9d756cd389e3bfee69d022f4bf470d7e1f
$ sudo docker run -it my_httpd2
ok Starting OpenBSD Secure Shell server: sshd. root@7d615ebbcf92:/usr/local/apache2# ps agxuwww
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.4 0.0 3368 2668 pts/0 Ss 03:43 0:00 /bin/bash
root 14 0.0 0.0 10684 2136 ? Ss 03:43 0:00 /usr/sbin/sshd
root 33 0.0 0.0 6956 3420 ? Ss 03:43 0:00 /usr/local/apache2/bin/httpd
daemon 34 0.0 0.0 235952 3576 ? Sl 03:43 0:00 /usr/local/apache2/bin/httpd
daemon 35 0.0 0.0 235952 3576 ? Sl 03:43 0:00 /usr/local/apache2/bin/httpd
daemon 36 0.0 0.0 235952 3576 ? Sl 03:43 0:00 /usr/local/apache2/bin/httpd
root 118 0.0 0.0 5088 2164 pts/0 R+ 03:43 0:00 ps agxuwww
1+ Done /usr/local/apache2/bin/httpd code:shell
$ telnet 172.17.0.2 80
Trying 172.17.0.2...
Connected to 172.17.0.2.
Escape character is '^]'.
GET /index.html
MUTOH's httpd
Connection closed by foreign host.
疑問点
元々のhttpdイメージは、runで起動した時にhttpdが起動していた。
commitで更新したイメージは、runで起動した時に/bin/bashが動く。
httpd(,sshdも)の起動設定をどうするべきかが良くわからない。
げんざいの~/.bashrcに記述する方法は、無理矢理すぎる。
参考:作業用Dockerイメージで作業を行う際の便利な設定
安全側には倒していないので、使う場合は注意が必要
code:shell
# apt install \
# ネットワーク調査のためのifconfig, netstatなどをインストール \
net-tools \
# 動作しているプロセスを調べるためにpsをインストール \
procps \
# 外部からログインして設定するためにsshdをインストール
ssh \
# 設定を編集するためにエディタvimをインストール
vim \
# tmuxをインストール
tmux
# ssh経由でrootでログインするために、パスワードをつけておく
# passwd
New password:
Retype new password:
passwd: password updated successfully
code:/etc/ssh/sshd_config.diff
# diff -u /etc/ssh/sshd_config{.20201109,}
--- /etc/ssh/sshd_config.20201109 2020-11-09 03:22:04.706382676 +0000
+++ /etc/ssh/sshd_config 2020-11-09 03:26:31.082270880 +0000
@@ -30,6 +30,7 @@
+PermitRootLogin yes
code:~root/.tmux.conf
set-option -g prefix C-z
unbind C-b
bind C-z send-prefix