1
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でよく使うコマンド(自分用)

1
Posted at

備忘録(完全自分用)

ログインコマンド

$ docker login -u (DockerのID) -p (Dockerのパスワード)

稼働しているコンテナの確認

$ docker ps 
or
$ docker container ls 
CONTAINER ID        IMAGE                       COMMAND                  CREATED             STATUS              PORTS                    NAMES
764ed8babe90        jun3030/dockerrepo:latest   "go run /echo/main.go"   37 minutes ago      Up 2 minutes        0.0.0.0:9000->8080/tcp   frosty_einstein

稼働しているコンテナ含め全てのコンテナの確認

$ docker ps -a
CONTAINER ID        IMAGE                       COMMAND                  CREATED             STATUS                     PORTS                    NAMES
764ed8babe90        jun3030/dockerrepo:latest   "go run /echo/main.go"   5 minutes ago       Up 5 minutes               0.0.0.0:9000->8080/tcp   frosty_einstein
33cb9e8d1d8b        first_docker:latest         "go run /echo/main.go"   19 hours ago        Exited (255) 2 hours ago   0.0.0.0:9000->8080/tcp   gracious_taussig
54c14f873d36        first_docker:latest         "go run /echo/main.go"   19 hours ago        Exited (2) 19 hours ago                             funny_moore

statusの欄に Up 5 minutes とあるのが稼働中のコンテナ

コンテナの起動

$ docker start コンテナのID
or
$ docker container run -d -p 9000:8080 jun3030/dockerrepo:latest

-d = バックグラウンドで実行
-p = ポートの指定 ホスト 9000 コンテナ = 8080
jun3030/dockerrepo = image
latest = タグ名

コンテナの停止

$ docker stop コンテナのID

アプリが稼働しているか確認
この場合-pオプションでホスト側の9000ポートからコンテナ側の8080ポートへポートフォワーディング出来るようにしている為、次のようにHTTPリクエストを発行できる。

$ curl http://localhost:9000/

Hello Docker!!

イメージのビルド

$ docker image build -t イメージ名:タグ名 Dockerfile配置ディレクトリのパス

-t = 名前をつけるときに使う
-f = docker image build コマンドはデフォルトでDockerFileというドッカーファイルを探しに行きます。そうでない名前のdouckerFileを利用する場合に-fを使用する。
Dockerfile配置ディレクトリのパス = ディレクトリにDockerfileがないと実行出来ない

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