Docker コマンドとかメモ
Docker のコマンドとかのメモ
取得できる docker image の取得
$ docker search {keyword}
docker image の取得
$ docker pull {image}
docker image の確認
$ docker images
コンテナの起動
$ docker run --name {container name} -it {docker image} {command)}
※ -it: 起動したコンテナをターミナルから操作する為に付けた
※ {command} は --entrypoint {command} とするのが行儀良いらしい
option 説明
- i, --interactive: keep STDIN open even if not attached. インタラクティブモード
- t, --tty: Allocate a pseudo-TTY. 仮想 tty を用意する
- h: ホストネーム付ける
- e: 環境変数を渡す 例.) $ docker run -it {image} -e ENV_VAL=value {command}
停止したコンテナの起動
$ docker start {docker name} -t
※ -i を付けるとコンテナへアタッチできる
※ -a では1コマンド実行できる
起動後のコンテナへログインする
$ docker exec -it {container name} {command (ex: /bin/sh)}
Docker image の作成
$ docker build -t {image name} {Dockerfile path}
Docker レジストリにログインする
$ docker login {host name}
image の名前を変更する (名前 == `$ docker images` で REPOSITORY として表示されるところ)
$ docker tag {変更前 name} {変更後 name}
※レジストリに登録する時の命名規則
{registry}/{image name}:{version}
Docker レジストリに登録する
$ docker push {image name}
コンテナの標準出力を見る
$ docker logs {container name}
デタッチモードで実行
$ docker-compose up -d
終了
$ docker-compose down
ネットワークを見る
$ docker network ls
コンテナとホスト間でコピー
$ docker cp {copy元 file} {copy先 file}
※ docker 側はファイルの前にコンテナIDを付ける {container id}:{file path}