3
2

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】Docker基本コマンド一覧

Last updated at Posted at 2022-03-12

はじめに

 本記事は、プログラミング初学者、学習を進めていて疑問に思った点について調べた結果を備忘録も兼ねてまとめたものです。
 そのため、記事の内容に誤りが含まれている可能性があります。ご容赦ください。
 間違いを見つけた方は、お手数ですが、ご指摘いただけますと幸いです。

Docker基本コマンド一覧

// イメージ関連
検索
  docker search [OPTIONS] 検索ワード
e.g.
  docker search ubuntu


ダウンロード
  docker pull [OPTIONS] イメージ名:[TAG]
e.g.
 docker pull docker/whalesay
 ※Tagを指定しない場合はlatestがpullされる


イメージ一覧
 docker images [OPTIONS]
e.g.
 $ docker images
 REPOSITORY    TAG       IMAGE ID       CREATED        SIZE
 hello-world   latest    18e5af790473   5 months ago   9.14kB
 my_whalesay   latest    6b362a9f73eb   6 years ago    247MB
 my_whalesay   ver1      6b362a9f73eb   6 years ago    247MB
 // digestsを表示
  docker images --digests hello-world


イメージの確認
 docker inspect [OPTIONS] イメージID
e.g.
docker inspect 18e5af790473


イメージ削除
 docker rmi [OPTIONS] イメージID
e.g.
 docker rmi 18e5af790473


ヒストリー確認
 docker history [OPTIONS] イメージID
e.g.
 docker history 18e5af790473




// コンテナ関連
生成と起動
 docker run [OPTIONS] イメージ名[:TAG] [ARG]
e.g.
 docker run docker/whalesay cowsay Hello!


ネットワーク
 docker run [OPTIONS] イメージ名[:TAG] [ARG]
e.g.
// ポートマッピング(-dはバックグラウンド起動)
 docker run -d -p 80:8080 httpd
// DNSサーバ指定
 docker run --dns=192.168.3.3 httpd
// ホスト名の設定
 docker run -it --hostname=mo-sample.com --add-host=test.com:192.168.2.3 ubuntu
// MACアドレスの指定
 docker run -it --mac-address="88:e9:fe:56:bd:65" ubuntu
// ホスト名とIPアドレス定義
 docker run -it --add-host=sample.com:192.168.3.3 ubuntu
// ロギング・ドライバの設定(docker logsでログが表示されない時に使用した)
 docker run -it --name mycentos --log-driver=json-file centos:8 /bin/bash


リソースを指定
 docker run [OPTIONS] イメージ名[:TAG] [ARG]
e.g.
 docker run --cpu-shares=256 --memory=512m ubuntu


稼働コンテナを一覧表示
 docker ps [OPTIONS]
e.g.
 docker ps
// 全て表示
 docker ps -a


コンテナの稼働確認
 docker stats コンテナID
e.g.
 docker stats 18e5af790473


停止
 docker stop [OPTIONS] コンテナID
e.g.
 docker stop 18e5af790473


再起動
 docker restart [OPTIONS] コンテナID
e.g.
 docker restart  18e5af790473


削除
 docker rm [OPTIONS] コンテナID
e.g.
 docker rm 18e5af790473
// 一括削除
 docker rm --force $(docker ps -aq)


稼働コンテナで実行
 docker exec [OPTIONS] コンテナID COMMAND [ARG]
e.g.
 docker exec -it ubuntu /bin/bash


稼働コンテナへ接続
 docker attach コンテナID
e.g.
 docker attach 18e5af790473




ログの出力
docker logs コンテナID
リアルタイムログの出力
docker logs -f コンテナID
データの永続化
// ホスト側のdocker管理ディレクトリ以下をコンテナにマウント
docker run -d --name sample -v my-vol:/app nginx:latest
3
2
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
3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?