LoginSignup
2
2

More than 5 years have passed since last update.

Debian(Jessie)をdocker(/sbin/init)で起動

Last updated at Posted at 2015-11-18

dockerを/sbin/initで実行

前回の記事でWheezyはかなりキレイに起動したのでならばJessieでもとやってみました。

debian + apache2 + php5

バージョンを前回7.9だったのを今回は8.2に変更します。
Jussisから/sbin/initは無くなったのでgettyの止め方が分からない・・・

Dockerfile
FROM debian:8.2

MAINTAINER takara

WORKDIR /root/

ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update
RUN apt-get -y install apache2 php5
ENV DEBIAN_FRONTEND dialog

EXPOSE 80

CMD ["/sbin/init", "3"]

ビルド

$ docker build -t deb_init:8.2 .

常駐実行

デーモンで実行

$ docker run -d --name deb_init -h deb_init deb_init:8.2

中に入ってプロセスを確認

$ docker exec -it deb_init bash
root@deb_init:~# ps aux
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root         1  1.5  0.4  28160  4192 ?        Ss   23:18   0:00 /sbin/init 3
root        21  0.6  0.3  31172  3368 ?        Ss   23:18   0:00 /lib/systemd/systemd-journald
root        26  0.7  0.2  38900  2984 ?        Ss   23:18   0:00 /lib/systemd/systemd-udevd
root        47  0.0  0.1  12836  1836 ?        Ss   23:18   0:00 /sbin/agetty --noclear tty1 linux
root        50  0.0  0.1  12836  1844 ?        Ss   23:18   0:00 /sbin/agetty --noclear tty2 linux
root        53  0.0  0.1  12836  1828 tty6     Ss+  23:18   0:00 /sbin/agetty --noclear tty6 linux
root        54  0.0  0.1  12836  1832 ?        Ss   23:18   0:00 /sbin/agetty --noclear tty5 linux
root        56  0.0  0.1  12836  1904 tty4     Ss+  23:18   0:00 /sbin/agetty --noclear tty4 linux
root        58  0.0  0.1  12836  1864 tty3     Ss+  23:18   0:00 /sbin/agetty --noclear tty3 linux
root        84  0.2  2.1 219060 21536 ?        Ss   23:18   0:00 /usr/sbin/apache2 -k start
www-data    87  0.0  0.6 219084  7164 ?        S    23:18   0:00 /usr/sbin/apache2 -k start
www-data    88  0.0  0.6 219084  7164 ?        S    23:18   0:00 /usr/sbin/apache2 -k start
www-data    89  0.0  0.6 219084  7164 ?        S    23:18   0:00 /usr/sbin/apache2 -k start
www-data    90  0.0  0.6 219084  7164 ?        S    23:18   0:00 /usr/sbin/apache2 -k start
www-data    91  0.0  0.6 219084  7164 ?        S    23:18   0:00 /usr/sbin/apache2 -k start
root        95  0.6  0.3  20236  3204 ?        S    23:18   0:00 /bin/bash
root       111  0.0  0.2  17492  2056 ?        R+   23:18   0:00 ps aux

debian Wheezyの時と違ってttyが止められない :cry:
systemctl deisable getty@.serviceとかでもtty1しか止まらない。うーん。
でも起動後にsystemctl stop getty@tty1とかやると止まることを確認。仕方ないので止めるためのサービスを追加。

なんかもっと良い方法ないのかな?
ご存じの方、ご教授ください。 :sob:

asset/ttystop
#!/bin/bash
### BEGIN INIT INFO
# Provides:          ttystop
# Required-Start:
# Required-Stop:
# Should-Start:
# Default-Start: 3 4 5
# Default-Stop:
# X-Interactive:     true
# Short-Description: ttystop
### END INIT INFO
systemctl stop getty@tty1 getty@tty2 getty@tty3 getty@tty4 getty@tty5 getty@tty6

サービス登録

Dockerfile の下の方に以下のサービスを登録するコードを追加

COPY asset/ttystop /etc/init.d/
RUN chkconfig --add ttystop

再ビルド後起動

とりあえず、ttyは消えた

root@deb_init:~# ps aux
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root         1  1.7  0.4  28192  4432 ?        Ss   11:05   0:00 /sbin/init 3
root        25  0.8  0.3  31172  3460 ?        Ss   11:05   0:00 /lib/systemd/systemd-journald
root        27  0.8  0.3  38996  3188 ?        Ss   11:05   0:00 /lib/systemd/systemd-udevd
root        85  0.3  2.1 219060 21904 ?        Ss   11:05   0:00 /usr/sbin/apache2 -k start
www-data    88  0.0  0.7 219084  7260 ?        S    11:05   0:00 /usr/sbin/apache2 -k start
www-data    89  0.0  0.7 219084  7260 ?        S    11:05   0:00 /usr/sbin/apache2 -k start
www-data    90  0.0  0.7 219084  7260 ?        S    11:05   0:00 /usr/sbin/apache2 -k start
www-data    91  0.0  0.7 219084  7260 ?        S    11:05   0:00 /usr/sbin/apache2 -k start
www-data    92  0.0  0.7 219084  7260 ?        S    11:05   0:00 /usr/sbin/apache2 -k start
root        96  1.6  0.2  20236  3052 ?        S    11:05   0:00 /bin/bash
root       101  0.0  0.1  17492  2028 ?        R+   11:05   0:00 ps aux

止まらなかった(試した)コマンド

RUN systemctl disable getty-static
RUN systemctl disable getty@
RUN systemctl disable getty-static
RUN systemctl list-unit-files --type=service|grep getty
RUN ln -sf lib/systemd/system/getty@.service /etc/systemd/system/getty.target.wants/getty@tty2.service
RUN ln -sf lib/systemd/system/getty@.service /etc/systemd/system/getty.target.wants/getty@tty3.service
RUN ln -sf lib/systemd/system/getty@.service /etc/systemd/system/getty.target.wants/getty@tty4.service
RUN ln -sf lib/systemd/system/getty@.service /etc/systemd/system/getty.target.wants/getty@tty5.service
RUN ln -sf lib/systemd/system/getty@.service /etc/systemd/system/getty.target.wants/getty@tty6.service
RUN systemctl disable getty@tty1
RUN systemctl disable getty@tty2
RUN systemctl stop getty@tty3
RUN systemctl stop getty@tty4
RUN systemctl stop getty@tty5
RUN systemctl stop getty@tty6

( ̄ヘ ̄;)ウーン
正解は何だろう?

参考サイト

systemd FAQ

2
2
2

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
2
2