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?

More than 3 years have passed since last update.

Dockerコマンドはじめの一歩

Last updated at Posted at 2021-07-04

下記、dockerを学ぶ際に理解したコマンド群です。
適宜追加していきます。
ずっと下書きに残してた...


  • コンテナの起動
docker run <container>
# コンテナ名を任意のものにする
docker run --name <container_name>
  • ローカル上にダウンロード済のイメージ一覧を見る
docker images
  • イメージにタグ付けする
docker tag <origin_image> <new_image>:tag_name
  • イメージの情報を確認する
docker inspect <image>
  • ローカル上のイメージを削除する
docker rmi <image>
  • イメージを取得する
docker pull <image>
  • DockerFileからイメージをビルドする
docker build -t <tag_name> <build_context_path>
  • コンテナの実行をバックグラウンドでおこない、ポートを外部公開させる
docker run --name <container> -d -p <port_by_host>:<port_by_container> <image>
# -d デタッチモード
# -p コンテナのポートを公開させる
  • バインドマウントを利用する
docker run --name <container> -d \
-v <host_dir>:<container_mount_point>:<options> \
-p <port_by_host>:<port_by_container> <image>
  • コンテナのシェルに接続する
docker attach <container>
# もしくは以下
# docker exec -it <container> /bin/bash
  • コミットする(コンテナの作業状態をイメージとして残す)
docker commit <container> <image>:<tag>

  • DockerFileの書き方
FROM 元となるイメージ
RUN buildされるときに実行されるコマンド
CMD コンテナ起動時に実行されるコマンド
0
0
2

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?