0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Dockerでよく使うコマンド集

Last updated at Posted at 2020-06-20

基本的なコマンド

イメージ作成系

Current Directory 内の Dockerfile をビルドしてイメージ作成

$ docker build ./

ビルドを最初からやり直し

$ docker build --no-cache .

コンテナ作成系

イメージからコンテナを作成(起動はさせない)

$ docker create イメージ名

コンテナ起動系

作成済みコンテナを起動

docker start コンテナ名

イメージからコンテナの起動+接続

$ docker run -it イメージ名 bash

#### イメージからコンテナを起動(名前付き)+接続
```Console
$ docker container run -it --name コンテナ名 イメージ名名 bash

起動済みコンテナへ接続

$ docker exec -it コンテナ名 bash

確認系

イメージの確認

$ docker images

起動中コンテナの一覧表示

$ docker ps

起動中コンテナの ID のみ表示

$ docker ps -q

ポートフォワードの関係性

$ docker port コンテナ名

コンテナの操作

ホストの/var/www をコンテナ内の/var/html からアクセスできるように共有

$ docker run -it -v /var/www:/var/html イメージ名 bash

ホスト 8080 番 port への通信をコンテナ 80 番 port へ転送

docker run -it -p 8080:80 イメージ名 bash

停止

コンテナの停止

$ docker stop コンテナID

起動中コンテナをすべて停止

$ docker stop $(docker ps -q)

コンテナの再起動

$ docker restart コンテナ名

削除

コンテナを削除

$ docker rm コンテナ名

イメージを削除

$ docker rmi IMAGE

DockerHub 関連

イメージの pull

$ docker pull ユーザ名/レポジトリ名

イメージの push

$ docker push ユーザ名/レポジトリ名
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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?