0
1

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 5 years have passed since last update.

Dockerコマンドメモ

Last updated at Posted at 2019-07-31

基本操作

イメージの取得(pull)

DockerHubからイメージを取得

$ docker pull ${イメージ名}(:${タグ})

# centosの最新イメージを取得
$ docker pull centos

# centosのバージョン6のイメージを明示的に取得
$ docker pull centos:6

イメージの登録(push)

DockerHubにイメージを登録

$ docker push ${イメージ名}(:${タグ})

イメージの確認(images)

$ docker images

イメージの削除(rmi)

$ docker rmi ${イメージID}

コンテナの作成・起動(run)

作成・起動のみ

$ docker run ${イメージID}

起動後、ターミナルに接続

$ docker run -it ${イメージID} bash

コンテナに名前を付ける

$ docker run ${イメージID} --name ${コンテナ名}

マウント

$ docker run ${イメージID} -v ${ホスト上のパス}:${コンテナ上のパス}

# 全部のせ
$ docker run --name test -v /home/kurita-shougo/workspace/test:/app/test -it 87f18086c4e7 bash
Docker for Windowsでマウントしたい場合 Shared Drives設定を入れてDockerを再起動 ![d-1.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/231600/cdbd33ba-0e39-e17c-2b70-709313e9bc90.png) ``` $ docker run --name test -v c:/workspace/test:/app/test -it 87f18086c4e7 bash ```

コンテナの確認(ps)

$ docker ps (-a)

-a をつけると起動してないコンテナも表示する

コンテナの削除(rm)

$ docker rm ${コンテナ名} or ${コンテナID}

コンテナの停止(stop)

$ docker stop ${コンテナ名} or ${コンテナID}

コンテナの再起動(start)

$ docker start ${コンテナ名} or ${コンテナID}

コンテナへのログイン(attach)

$ docker attach ${コンテナ名} or ${コンテナID}

コンテナからログアウト

コンテナ上での操作

コンテナを停止しない場合

ctrl + p +q

コンテナを停止する場合

$ exit

応用操作

REPOSITORY名変更

$ docker tag ${変更したいイメージのID} ${イメージ名}:${タグ名}
これで設定したものが複製されるので元のイメージは削除する。
$ docker rmi ${IMAGE ID}

0
1
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
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?