LoginSignup
15
14

More than 3 years have passed since last update.

作業用Dockerコンテナ起動コマンドのメモ

Posted at

1行メモ。

$ docker run -it --rm --name console --user `id -u`:`id -g` --volume `pwd`:`pwd` --workdir `pwd` <image> bash

改行入れると、こんな感じ。

docker run \
  -it \
  --rm \
  --name console \
  --user `id -u`:`id -g` \
  --volume `pwd`:`pwd` \
  --workdir `pwd` \
  <image> bash

補足説明

  • -it で、 --interactive--ttyの略。要は対話型コンソールで起動するオプション
  • --rmで、コンテナ終了時、自動削除。
  • --name は、コンテナの名前。お好きな名前でどうぞ。
  • --user `id -u`:`id で、今現在のUser IDでコンテナに入る。同一ユーザでファイル操作できるように。
  • --volume `pwd`:`pwd`で、今現在のディレクトリをそのままマウントする。コンテナ内でファイル修正しても、そのままホスト側に残せます。
  • --workdir `pwd`で、作業用ディレクトリ(コンテナ内)を指定。コンテナ起動直後のカレントディレクトリとなる。
  • <image>は、お好きなイメージIDをどうぞ。ex) node, python, java...
  • bashがNGの場合は、shで起動してみて。

その他

さらに、--network hostとか追加しても良いかも。コンテナ内で、Webサーバ起動して、外部からアクセスも可能になる。

15
14
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
15
14