0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Dockerのコンテナ操作コマンド

Posted at

Dockerのコンテナ操作コマンド

イメージの取得(pull)

イメージの取得(pull)
$ docker pull centos

コンテナの実行(run)

イメージの実行(run)
$ docker run centos echo "hello world"
hello world

コンテナをデーモンとして実行(run -d)

イメージをデーモンとして実行(run-d)
$ docker run -d centos free -s 3
d6428ae88db3ded1764e6bc5a28f9d733cc8f10828c13680679c3f3f7cc2cf40

実行中コンテナの表示(ps)

実行中コンテナの表示(ps)
$ docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
d6428ae88db3        centos              "free -s 3"         11 minutes ago      Up 29 seconds                           stoic_bell

ログ等で動作確認(logs)

ログ等で動作確認(logs)
$ docker logs d642
              total        used        free      shared  buff/cache   available
Mem:       13001564      525996    11012892        1068     1462676    12249868
Swap:       4194304           0     4194304

              total        used        free      shared  buff/cache   available
Mem:       13001564      525992    11012892        1068     1462680    12249868
Swap:       4194304           0     4194304

コンテナの停止(stop/kill)

コンテナの停止(stop/kill)
$ docker stop d642
d642

再度、実行中コンテナの表示。停止したので表示なし。

実行中コンテナの表示(ps)
$ docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

停止したコンテナはイメージとして残ってるので表示して確認。(ps -a)

停止したコンテナの表示(ps-a)
$ docker ps -a
CONTAINER ID        IMAGE               COMMAND                CREATED             STATUS                          PORTS               NAMES
d6428ae88db3        centos              "free -s 3"            12 minutes ago      Exited (137) 9 seconds ago

停止中コンテナの再開(start)

停止中コンテナの再開(start)
$ docker start d642
d642

ログ等で動作確認(logs)

ログ等で動作確認(logs)
$ docker logs d642
              total        used        free      shared  buff/cache   available
Mem:       13001564      525996    11012892        1068     1462676    12249868
Swap:       4194304           0     4194304

              total        used        free      shared  buff/cache   available
Mem:       13001564      525992    11012892        1068     1462680    12249868
Swap:       4194304           0     4194304
0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?