数日前からDockerを勉強している老眼SEです。
Dockerの仕組みも用語もあやふやの超初心者で多分に間違いもありそうですが、取り敢えず動かしています。
今回はコンテナの操作です。
- コンテナの作成と起動
- コンテナ一覧
- コンテナのデタッチ
- コンテナへのアタッチ
- コンテナの起動
- コンテナの停止
- コンテナの再起動
- コンテナの使用リソース
- コンテナ名の変更
- コンテナの削除
コンテナの作成して起動するにはdocker runコマンドを実行します。
docker runには多数のオプションがあってよく分かりませんが取り敢えず基本的なところで、コンテナ名をmycentos6で作成して起動、アタッチします。
1 2 |
$ docker run -it --name mycentos6 centos:6 /bin/bash [root@fb942762e4bf /]# |
作成されたコンテナの一覧表示です。
1 2 3 4 |
$ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES fb942762e4bf centos:6 "/bin/bash" 41 minutes ago Up 41 minutes mycentos6 4efef60d9ed0 centos:6 "/bin/bash" About an hour ago Up About an hour infallible_cray |
1 2 3 4 5 6 7 8 |
$ docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES a39c09a29c8c centos:6 "/bin/bash" 2 minutes ago Exited (0) 2 minutes ago mycentos-2 fb942762e4bf centos:6 "/bin/bash" 40 minutes ago Up 40 minutes mycentos6 4efef60d9ed0 centos:6 "/bin/bash" About an hour ago Up About an hour infallible_cray 119a3a22a319 centos "/bin/bash" 6 hours ago Exited (0) 6 hours ago compassionate_morse 1d65fc64000f centos:6 "/bin/bash" 6 hours ago Exited (0) 6 hours ago objective_stonebraker 05a6e1c7a4f6 hello-world "/hello" 7 hours ago Exited (0) 7 hours ago loving_beaver |
デタッチはCtrl+p Ctrl+q
1 2 |
$ docker attach mycentos6 [root@fb942762e4bf /]# |
1 2 3 4 5 6 7 8 |
$ docker start 119a3a22a319 119a3a22a319 $ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES fb942762e4bf centos:6 "/bin/bash" 58 minutes ago Up 58 minutes mycentos6 4efef60d9ed0 centos:6 "/bin/bash" About an hour ago Up About an hour infallible_cray 119a3a22a319 centos "/bin/bash" 6 hours ago Up 5 seconds compassionate_morse |
1 2 3 4 5 6 7 |
$ docker stop 119a3a22a319 119a3a22a319 $ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES fb942762e4bf centos:6 "/bin/bash" About an hour ago Up About an hour mycentos6 4efef60d9ed0 centos:6 "/bin/bash" About an hour ago Up About an hour infallible_cray |
1 2 3 4 5 6 7 8 9 10 11 12 |
$ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES fb942762e4bf centos:6 "/bin/bash" About an hour ago Up About an hour mycentos6 4efef60d9ed0 centos:6 "/bin/bash" About an hour ago Up About an hour infallible_cray $ docker restart 4efef60d9ed0 4efef60d9ed0 $ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES fb942762e4bf centos:6 "/bin/bash" About an hour ago Up About an hour mycentos6 4efef60d9ed0 centos:6 "/bin/bash" About an hour ago Up 5 seconds infallible_cray |
1 2 3 4 |
$ docker stats --no-stream CONTAINER CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS fb942762e4bf 0.00% 352 KiB / 3.844 GiB 0.01% 2.12 kB / 648 B 0 B / 0 B 1 4efef60d9ed0 0.00% 356 KiB / 3.844 GiB 0.01% 648 B / 648 B 0 B / 0 B 1 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
$ docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES fb942762e4bf centos:6 "/bin/bash" About an hour ago Up About an hour mycentos6 4efef60d9ed0 centos:6 "/bin/bash" About an hour ago Up 9 minutes infallible_cray 119a3a22a319 centos "/bin/bash" 6 hours ago Exited (137) 11 minutes ago compassionate_morse 1d65fc64000f centos:6 "/bin/bash" 6 hours ago Exited (0) 6 hours ago objective_stonebraker $ docker rename 119a3a22a319 mycentos7 $ docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES fb942762e4bf centos:6 "/bin/bash" About an hour ago Up About an hour mycentos6 4efef60d9ed0 centos:6 "/bin/bash" About an hour ago Up 10 minutes infallible_cray 119a3a22a319 centos "/bin/bash" 6 hours ago Exited (137) 12 minutes ago mycentos7 1d65fc64000f centos:6 "/bin/bash" 6 hours ago Exited (0) 6 hours ago objective_stonebraker |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
$ docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES fb942762e4bf centos:6 "/bin/bash" About an hour ago Up About an hour mycentos6 4efef60d9ed0 centos:6 "/bin/bash" About an hour ago Up About a minute infallible_cray 119a3a22a319 centos "/bin/bash" 6 hours ago Exited (137) 3 minutes ago compassionate_morse 1d65fc64000f centos:6 "/bin/bash" 6 hours ago Exited (0) 6 hours ago objective_stonebraker 05a6e1c7a4f6 hello-world "/hello" 7 hours ago Exited (0) 7 hours ago loving_beaver $ docker rm 05a6e1c7a4f6 05a6e1c7a4f6 $ docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES fb942762e4bf centos:6 "/bin/bash" About an hour ago Up About an hour mycentos6 4efef60d9ed0 centos:6 "/bin/bash" About an hour ago Up About a minute infallible_cray 119a3a22a319 centos "/bin/bash" 6 hours ago Exited (137) 3 minutes ago compassionate_morse 1d65fc64000f centos:6 "/bin/bash" 6 hours ago Exited (0) 6 hours ago objective_stonebraker |