LoginSignup
4
3

More than 5 years have passed since last update.

dockerのお勉強備忘録

Last updated at Posted at 2014-08-20

すっかりdockerが記憶から消えたので、参考サイトの通りに
コマンドを打ってdockerを再勉強してみようと思う。

入力したコマンドは記録しておく。

随分前にインストールしたのでいきなりhello worldを出力して終了するコマンド。
sudo docker run centos /bin/echo "Hello World"
Hello World

docker上のシェルにログインしたい場合は -i -hオプションをつけてdocker起動

sudo docker run -i -t centos /bin/bash
cat /etc/redhat-release
CentOS Linux release 7.0.1406 (Core)
bash-4.2# exit

立ち上げたコンテナ内のシェルに入るには
sudo docker run -i -t centos /bin/bash
bash-4.2#

バックグラウンドコンテナを起動するには

sudo docker run -d centos /bin/bash

現在稼働中のコンテナを調べるコマンド
sudo docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
2bccf43d9d91 centos:centos7 /bin/bash 23 seconds ago Up 23 seconds

ctl+p、ctl+qで抜けたコンテナに戻る場合(attach)

sudo docker attach 2bccf43d9d91
bash-4.2#

終了したコンテナも含めて表示
sudo docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
eebbc62fd3f5 centos:centos7 /bin/bash 3 minutes ago Exit 0 naughty_feynman
49e832500481 centos:centos7 /bin/bash 9 minutes ago Up 9 minutes silly_wright
a53fc1da43d2 centos:centos7 /bin/echo Hello Worl 10 minutes ago Exit 0 furious_pasteur

意外に簡単だ。

参考 CentOS 6.5 で Docker を使ってみる
参考 Dockerに入門してみた

4
3
0

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
4
3