dockerのコンテナ起動方法

単純な起動方法
# docker run centos /bin/echo 'hello world'
hello world
#
docker run
コンテナ内でプロセスを実行する
centos
レポジトリ名
/bin/echo 'hello world'
実行コマンド
TAGが異なるレポジトリがある場合の起動方法
# docker images
REPOSITORY TAG    IMAGE ID     CREATED       VIRTUAL SIZE
centos     latest 0c752394b855 2 weeks ago   124.1 MB
centos     6.4    539c0211cd76 15 months ago 300.6 MB
#
「:」以降にTAG名を記述し使い分ける。
# docker run centos:latest cat /etc/redhat-release
CentOS release 6.5 (Final)
# docker run centos:6.4 cat /etc/redhat-release
CentOS release 6.4 (Final)
#
この方法で実行すると指定したコマンドをフォアグラウンドで実行する。またこのコマンドが終了するとコンテナーが停止してしまう。
コンテナをバックグラウンドで実行する方法
# docker run -d centos /bin/sh -c "while true; do echo hello world; sleep 1; done"
fdeb793234d7636d3e8c952c200b1476bde04a1aa48b20e551027d7823befa4b
#
-d(-detach)オプションを使用することでデタッチモードで実行する。この際の出力はコンテナーのIDが出力されている。

0 件のコメント :

コメントを投稿