LoginSignup
9
8

More than 5 years have passed since last update.

オレオレDockerメモ(基本操作編)

Posted at

Example

# -i: 標準入力でコンテナに接続
# -t: 擬似端末を割り当てる
# -v: ホストとコンテナ間でデータ同期
# --rm: コンテナからのデタッチ時にコンテナを削除
# exit でターミナル終了&コンテナ停止
# ctrl+P+Q 同時押しでターミナル終了&コンテナ未停止
$ docker run -it --name centos -v /tmp:/tmp --rm centos:7 /bin/bash

# -d: バックグラウンドで起動
$ docker run -d --name background centos:7 ping 127.0.0.1 -c 50
$ docker logs -ft background

# -P: ランダムにポートフォワーディング( docker ps でポート確認)
# -p: 任意のポートフォワーディング
$ docker run --name nginx -d -p 8080:80 nginx
$ docker exec -it nginx /bin/bash

Commands

$ docker version

Client:
 Version:      1.12.0
 API version:  1.24
 Go version:   go1.6.3
 Git commit:   8eab29e
 Built:        Thu Jul 28 21:15:28 2016
 OS/Arch:      darwin/amd64

Server:
 Version:      1.12.0
 API version:  1.24
 Go version:   go1.6.3
 Git commit:   8eab29e
 Built:        Thu Jul 28 21:15:28 2016
 OS/Arch:      linux/amd64

# ローカルイメージの表示
$ docker images

# イメージの取得
$ docker pull <name>[:tag]

# コンテナの作成と実行
$ docker run [options] <name>[:tag] [command] [args]

# コンテナの一覧
$ docker ps [options]

# コンテナのログ確認(PID1のあらゆる標準出力)
$ docker logs [options] <container>

# コンテナへのアタッチ(PID1のプロセスを操作)
$ docker attash <container>

# コンテナへのプロセス追加(ターミナルを終了してもコンテナ未停止)
$ docker exec [options] <container> <command> [args]

# コンテナの停止
$ docker stop <container>

# コンテナの強制停止
$ docker kill <container>

# コンテナの削除
$ docker rm <container>

# イメージ/コンテナ/タスク の情報を表示
$ docker inspect [options] image|container|task
9
8
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
9
8