0
0

More than 1 year has passed since last update.

Dockerコマンド オプション

Posted at

 Dockerコマンドオプションに関するチートシートです。学習の備忘録ですが、何かの役に立てば嬉しいです。

Dockerコマンド
-v <host>:<container>

#example
$ docker run -it -v ~/Desktop/sample_dir:new_dir <image> bash

 オプションでホストのファイルシステムをコンテナにマウントすることができます。

 Dockerコンテナはできるだけ軽い方が良いため、hostのファイルシステムをマウントすることがとても多いです。

 例では、Dockerコンテナ起動時にホストのsample_dirフォルダをコンテナのnew_dirフォルダがマウントするように指定しています。


Dockerコマンド
-u <user id>:<group id>

#example
$ docker run -it -u $(id -u):$(id -g) \ -v ~/Desktop/sample_dir:new_dir <image> bash

 ユーザIDとグループIDを指定してコンテナをrunします。

Dockerコマンド
-p <host_port>:<container_port>

#example
$ docker run -it -p 8888:8888 --rm jupyter/datascience-notebook bash

ホストのポートをコンテナのポートに繋げる

Dockerコマンド
--cpus <# of CPUs>

#example
$ docker run -it --cpus 4 --memory 2g ubuntu bash

コンテナがアクセスできるCPUの上限を設定する

Dockerコマンド
--memory <byte>

#example
$ docker run -it --rm --cpus 4 --memory 2g ubuntu bash

コンテナがアクセスできるメモリの上限を設定する

Dockerコマンド
$docker inspect <container>

Dockerコンテナで使用できるリソースを確認することができる

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