このドキュメントで説明するソフトウェアは、Extended SupportまたはSustaining Supportのいずれかにあります。 詳細は、https://www.oracle.com/us/support/library/enterprise-linux-support-policies-069172.pdfを参照してください。
Oracleでは、このドキュメントに記載されているソフトウェアをできるだけ早くアップグレードすることをお薦めします。
構成されているコンテナを表示するには、ホストでlxc-lsコマンドを使用します。
[root@host ~]# lxc-ls
ol6ctr1
ol6ctr2
ホスト・システム上で動作しているコンテナを表示するには、--activeオプションを指定します。
[root@host ~]# lxc-ls --active
ol6ctr1
コンテナの状態を表示するには、ホストでlxc-infoコマンドを使用します。
[root@host ~]# lxc-info -n ol6ctr1
state: RUNNING
pid: 10171
コンテナの状態は、ABORTING
、RUNNING
、STARTING
、STOPPED
またはSTOPPING
のいずれかです。 lxc-infoによってコンテナがRUNNING
状態であると表示されても、/usr/sbin/sshd
または/sbin/mingetty
プロセスがコンテナで起動していなければ、ログインすることはできません。 コンテナで/sbin/init
プロセスが最初にネットワーキングおよび構成済の他の様々なサービスを開始する時間を考慮しておく必要があります。
ホストからコンテナのプロセスの状態を表示するには、ps -ef --forestを実行してlxc-start
プロセス以下のプロセス・ツリーを確認するか、lxc-attachコマンドを使用してコンテナ内でpsコマンドを実行します。
[root@host ~]#ps -ef --forest
UID PID PPID C STIME TTY TIME CMD ... root 3171 1 0 09:57 ? 00:00:00 lxc-start -n ol6ctr1 -d root 3182 3171 0 09:57 ? 00:00:00 \_ /sbin/init root 3441 3182 0 09:57 ? 00:00:00 \_ /sbin/dhclient -H ol6ctr1 ... root 3464 3182 0 09:57 ? 00:00:00 \_ /sbin/rsyslogd ... root 3493 3182 0 09:57 ? 00:00:00 \_ /usr/sbin/sshd root 3500 3182 0 09:57 pts/5 00:00:00 \_ /sbin/mingetty ... /dev/console root 3504 3182 0 09:57 pts/1 00:00:00 \_ /sbin/mingetty ... /dev/tty1 root 3506 3182 0 09:57 pts/2 00:00:00 \_ /sbin/mingetty ... /dev/tty2 root 3508 3182 0 09:57 pts/3 00:00:00 \_ /sbin/mingetty ... /dev/tty3 root 3510 3182 0 09:57 pts/4 00:00:00 \_ /sbin/mingetty ... /dev/tty4 ... [root@host ~]#lxc-attach -n ol6ctr1 -- /bin/ps aux
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 1 0.0 0.1 19284 1516 ? Ss 04:57 0:00 /sbin/init root 202 0.0 0.0 9172 588 ? Ss 04:57 0:00 /sbin/dhclient root 225 0.0 0.1 245096 1332 ? Ssl 04:57 0:00 /sbin/rsyslogd root 252 0.0 0.1 66660 1192 ? Ss 04:57 0:00 /usr/sbin/sshd root 259 0.0 0.0 4116 568 lxc/console Ss+ 04:57 0:00 /sbin/mingett root 263 0.0 0.0 4116 572 lxc/tty1 Ss+ 04:57 0:00 /sbin/mingetty root 265 0.0 0.0 4116 568 lxc/tty2 Ss+ 04:57 0:00 /sbin/mingetty root 267 0.0 0.0 4116 572 lxc/tty3 Ss+ 04:57 0:00 /sbin/mingetty root 269 0.0 0.0 4116 568 lxc/tty4 Ss+ 04:57 0:00 /sbin/mingetty root 283 0.0 0.1 110240 1144 ? R+ 04:59 0:00 /bin/ps aux
コンテナが正しく起動しているように見えない場合、ホストからそのプロセス・ツリーを調査すると、通常、問題の所在がわかります。
コンテナにログインしている場合、ps -efコマンドによる出力は次のようになります。
[root@ol6ctr1 ~]# ps -ef
UID PID PPID C STIME TTY TIME CMD
root 1 0 0 07:58 ? 00:00:00 /sbin/init
root 183 1 0 07:58 ? 00:00:00 /sbin/dhclient -H ol6ctr1 ...
root 206 1 0 07:58 ? 00:00:00 /sbin/rsyslogd -i ...
root 247 1 0 07:58 ? 00:00:00 /usr/sbin/sshd
root 254 1 0 07:58 lxc/console 00:00:00 /sbin/mingetty /dev/console
root 258 1 0 07:58 ? 00:00:00 login -- root
root 260 1 0 07:58 lxc/tty2 00:00:00 /sbin/mingetty /dev/tty2
root 262 1 0 07:58 lxc/tty3 00:00:00 /sbin/mingetty /dev/tty3
root 264 1 0 07:58 lxc/tty4 00:00:00 /sbin/mingetty /dev/tty4
root 268 258 0 08:04 lxc/tty1 00:00:00 -bash
root 279 268 0 08:04 lxc/tty1 00:00:00 ps -ef
プロセス番号がホストの同じプロセスの番号とは異なっており、それらはすべてコンテナのプロセス1 (/sbin/init
)の下位にあることに注意してください。
コンテナの実行を一時停止または再開するには、ホストでlxc-freezeおよびlxc-unfreezeコマンドを使用します。
[root@host ~]#lxc-freeze -n ol6ctr1
[root@host ~]#lxc-unfreeze -n ol6ctr1
ホストからは、lxc-stopコマンドを--nokillオプションで使用すると、コンテナを正常手順でシャットダウンできます。
[root@host ~]# lxc-stop --nokill -n ol6ctr1
別の方法として、コンテナへのログイン中に、haltまたはinit 0などのコマンドを実行できます。
[root@ol6ctr1 ~]# halt
Broadcast message from root@ol6ctr1
(/dev/tty2) at 22:52 ...
The system is going down for halt NOW!
lxc-console: Input/output error - failed to read
[root@host ~]#
例に示すとおり、ホストのシェル・プロンプトに戻ります。
プロセスを即座に終了してコンテナを停止するには、ホストでlxc-stopコマンドを-kオプションで使用します。
[root@host ~]# lxc-stop -k -n ol6ctr1
コンテナの動作をデバッグする場合、通常はコンテナを破棄してテンプレート・スクリプトの変更後に新しいバージョンを作成するため、lxc-stopを使用することが最も簡単な方法です。
コンテナの状態を監視するには、lxc-monitorコマンドを使用します。
[root@host ~]# lxc-monitor -n ol6ctr1
'ol6ctr1' changed state to [STARTING]
'ol6ctr1' changed state to [RUNNING]
'ol6ctr1' changed state to [STOPPING]
'ol6ctr1' changed state to [STOPPED]
コンテナが指定した状態に変更されるのを待機するには、lxc-waitコマンドを使用します。
lxc-wait -n $CTR -s ABORTING && lxc-wait -n $CTR -s STOPPED && \ echo "Container $CTR terminated with an error."