■ はじめに
Amazon ECR ~ 入門編 ~
https://dk521123.hatenablog.com/entry/2020/05/22/165711
でECRへの登録した。 今回は、レポジトリへのイメージ登録するためのコマンドを纏める。 なお、Docker Hub でも使える。
目次
【1】docker login 【2】docker image build 【3】docker image tag 【4】docker image push 【5】docker image pull 【6】docker image save 【7】docker image load 【8】docker container commit
【1】docker login
* ログイン
構文
docker login [オプション] [サーバ]
コマンド例
# --username:ユーザ名、--password:パスワード docker login --username admin --password password xxxx.xxx.ecr.us-west-2.amazonaws.com
セキュアに行うには...
# --password-stdin(標準出力からパスワードを設定) を使用する cat ~/.password.txt | docker login --username admin --password-stdin xxxx.xxx.ecr.us-west-2.amazonaws.com
【2】docker image build
* Dockerfile からイメージをビルド
https://docs.docker.jp/engine/reference/commandline/image_build.html
構文
# -t: タグを 名前:タグ の形式で指定 docker image build -t イメージ名[:タグ名] [Dockerfileが配置されているディレクトリパス]
コマンド例
docker image build -t hello-world-ecr
https://www.wakuwakubank.com/posts/270-docker-build-image/
【3】docker image tag
* タグづけする
構文
docker image tag [イメージID] [リポジトリ名]:[タグ]
コマンド例
docker image tag hello-world-ecr:latest xxxx.xxx.ecr.us-west-2.amazonaws.com/hello-world-ecr:latest
【4】docker image push
* コンテナイメージをリポジトリにプッシュする
構文
docker image push [コンテナ名]
コマンド例
docker image push xxxx.xxx.ecr.us-west-2.amazonaws.com/hello-world-ecr:latest
【5】docker image pull
* コンテナイメージをリポジトリからプルする * 旧コマンド「docker pull」
構文
docker image pull registry/repository[:tag]
コマンド例
# docker image pull registry/repository[:tag]
docker image pull xxxx.xxx.ecr.us-west-2.amazonaws.com/hello-world-ecr:latest
【6】docker image save
* Dockerイメージのexport * 旧コマンド「docker save」
構文
# Dockerイメージをtarファイルとして出力する docker image save [コンテナ名] -o [Tarファイル名].tar
コマンド例
docker image save hello-world-ecr:latest -o hello-world-ecr.tar
【7】docker image load
* Dockerイメージのimport * 旧コマンド「docker load」
構文
# tarファイルをDockerイメージとしてロードする docker image load -i [Tarファイル名].tar
コマンド例
docker image load -i hello-world-ecr.tar # 確認 docker image ls
参考文献
https://qiita.com/leomaro7/items/e5474e67a8e41536f0ff
【8】docker container commit
* イメージ作成 * 旧コマンド「docker commit」
構文
コマンド例
docker container commit fb31cf61cb2c admin/helloworld docker image ls REPOSITORY TAG IMAGE ID CREATED SIZE admin/helloworld latest 2f25f5844caa About a minute ago 199 MB docker container run -i -t admin/helloworld
参考文献
https://qiita.com/zembutsu/items/6e1ad18f0d548ce6c266
関連記事
Docker ~ 基礎知識編 ~
https://dk521123.hatenablog.com/entry/2020/04/24/160044
Docker ~ 入門編 ~
https://dk521123.hatenablog.com/entry/2023/02/25/000000
Docker ~ 基本編 / dockerコマンド ~
https://dk521123.hatenablog.com/entry/2020/04/13/000000
Docker ~ 基本編 / docker container コマンド ~
https://dk521123.hatenablog.com/entry/2022/01/20/000000
Docker ~ ファイルをコンテナにコピー ~
https://dk521123.hatenablog.com/entry/2022/04/27/000000
Amazon ECR ~ 入門編 ~
https://dk521123.hatenablog.com/entry/2020/05/22/165711
Terraform ~ AWS ECR ~
https://dk521123.hatenablog.com/entry/2023/05/23/002314