- docker container commit(コンテナからイメージ作成)
- docker container export(コンテナをtarファイル出力)
- docker image import(tarファイルからのイメージ作成)
- docker image save(イメージ保存)
- docker image load(イメージ読み込み)
- docker system prune(不要なイメージ/コンテナ削除)
- 参考資料
docker container commit(コンテナからイメージ作成)
$ docker container commit [オプション] コンテナ識別子 [イメージ名{[タグ名]}]
Options | Description |
---|---|
--author,-a | 作成者を指定 |
--message,-m | メッセージを指定する |
--change,-c | コミット時のDockerfile命令を指定 |
--pause,-p | コンテナを一時停止してコミットする |
実行例:コンテナからイメージ作成
docker@LesPaul:~$ docker container commit -a "Undercover" webfront undercover/webfront:1.0 sha256:8c8a00a3cdc8dc445b8569e759c7df4739867385a873dcd948a0b94d876acf22 docker@LesPaul:~$ docker image ls REPOSITORY TAG IMAGE ID CREATED SIZE undercover/webfront 1.0 8c8a00a3cdc8 33 seconds ago 109MB
実行例:イメージ詳細確認
docker@LesPaul:~$ docker image inspect undercover/webfront:1.0 ~中略~ "DockerVersion": "18.06.1-ce", "Author": "Undercover", ]
docker container export(コンテナをtarファイル出力)
$ docker container export コンテナ識別子
実行例:ファイル出力
docker@LesPaul:~$ docker container export webserver > latest.tar docker@LesPaul:~$ ls -la | grep latest -rw-rw-r-- 1 docker docker 111124992 10月 25 21:41 latest.tar
実行例:生成されたtarファイルの詳細確認
docker@LesPaul:~$ tar -tf latest.tar .dockerenv bin/ bin/bash bin/cat bin/chgrp bin/chmod bin/chown bin/cp ~中略~
docker image import(tarファイルからのイメージ作成)
$ docker image import ファイルまたはURL - [イメージ名[:タグ名]]
例:イメージ作成
$ cat latest.tar | docker image import - undercover/webfront:1.1
実行例:イメージ作成
docker@LesPaul:~$ docker image ls REPOSITORY TAG IMAGE ID CREATED SIZE undercover/webfront 1.1 aeab77eba79c 41 seconds ago 107MB
docker image save(イメージ保存)
$ docker image save [オプション] 保存ファイル名 [イメージ名]
実行例:イメージ保存
docker@LesPaul:~$ docker image save -o export.tar ubuntu docker@LesPaul:~$ ls -la | grep export -rw------- 1 docker docker 86647808 10月 25 21:53 export.tar
docker image load(イメージ読み込み)
$ docker image load [オプション]
例:イメージ読み込み
$ docker image load -i export.tar
docker system prune(不要なイメージ/コンテナ削除)
$ docker system prune [オプション]
Options | Description |
---|---|
--all,-a | 使用していないリソースを全て削除する |
--force,-f | 強制的に削除する |
実行例:不要なリソースの削除
docker@LesPaul:~$ docker system prune -a WARNING! This will remove: - all stopped containers - all networks not used by at least one container - all images without at least one container associated to them - all build cache Are you sure you want to continue? [y/N] y Deleted Containers: dd72a792e0a7c57a70b7442f827ec355d1e287e26df37299a6aca7667bdbf13c 7e287f339630b1d539c87ff0fa0b09f819233ecfc40ceda8982da56ff11d5f8b Deleted Images: untagged: ubuntu:latest untagged: ubuntu@sha256:de774a3145f7ca4f0bd144c7d4ffb2931e06634f11529653b23eba85aef8e378 deleted: sha256:cd6d8154f1e16e38493c3c2798977c5e142be5e5d41403ca89883840c6d51762 deleted: sha256:2416e906f135eea2d08b4a8a8ae539328482eacb6cf39100f7c8f99e98a78d84 deleted: sha256:7f8291c73f3ecc4dc9317076ad01a567dd44510e789242368cd061c709e0e36d deleted: sha256:4b3d88bd6e729deea28b2390d1ddfdbfa3db603160a1129f06f85f26e7bcf4a2 deleted: sha256:f51700a4e396a235cee37249ffc260cdbeb33268225eb8f7345970f5ae309312 deleted: sha256:a30b835850bfd4c7e9495edf7085cedfad918219227c7157ff71e8afe2661f63 untagged: undercover/webfront:1.0 deleted: sha256:8c8a00a3cdc8dc445b8569e759c7df4739867385a873dcd948a0b94d876acf22 deleted: sha256:9a4854d752ce57d494247e3263a4f3eaf75dd911d5dfc6e2825f0645d27473c4 untagged: undercover/webfront:1.1 deleted: sha256:aeab77eba79c324184a9ba49010e76f2b5b09937dd115e2b3844fe93b4bbaa27 deleted: sha256:45372a8a59012ec7eb0a11b8cc480523b2f437d5ef14c530097b6ce75d14466f untagged: nginx:latest untagged: nginx@sha256:9ad0746d8f2ea6df3a17ba89eca40b48c47066dfab55a75e08e2b70fc80d929e untagged: undercover/webserver:1.0 untagged: jenkins:latest untagged: jenkins@sha256:eeb4850eb65f2d92500e421b430ed1ec58a7ac909e91f518926e02473904f668 deleted: sha256:cd14cecfdb3a657ba7d05bea026e7ac8b9abafc6e5c66253ab327c7211fa6281 deleted: sha256:9047d4817dd4203ae4d456888aa5355bc526d274713d6f168359ba61b85b6c00 deleted: sha256:b6eeb6c0e550e93a8b6293a35b2a68931a2af1d21cf8fe8c53bd412359433fdc deleted: sha256:54a9d685504efad152c1032f37f76ee95bae30607f68bd0ff48a095ebec5d820 deleted: sha256:0b5e1c633ad7fa60f5185ff00ccbff9af3608ba336dc7c01868f9cd0dd8a7137 deleted: sha256:0373335894092868f06432433f14881bd6f09d851931d6e5090601a64e0466f3 deleted: sha256:b4e8f84d7b87e7994e49a190bc35871b23f76d9cab573308fa1ae7401c50dcc6 deleted: sha256:cde912e85b12d50e9e4d056ad3c8cb35853c60291dbe4b319dcd80bcd2ef243c deleted: sha256:8062b94ccb384de40b6777515f21b895be64218c5296bac3ee6db2ed4c5db9fe deleted: sha256:a3411e0c109af31befac78bcbd2aba26f893717f645df8d4828bf29772417bc0 deleted: sha256:fb1cc4fe4174cb86f9614cf9ee4c6cecad4c7f0c04ca52c95fd1a7d0d79471e8 deleted: sha256:1fe73f13106502d5c58cc444a71738c518b341fd667fc26058f3e473a3cc559f deleted: sha256:d3898f75e7b8a2a7e45bfdd351a00c4ad95b743861860635d702378fd073771d deleted: sha256:46ddeaf1e1efd81fd6cad11c44af4e4ba71cbab32b75f60f8647f025a8874315 deleted: sha256:4e9ac8670c1ea60c504c1dc22e38a177afd782a48e17e81e06ecf60a1c8f4ef0 deleted: sha256:76dc20911db5ba40907269c70aa4ef7caf207ea4aa23818b8db2ff83ba74e1e4 deleted: sha256:b4ff564f2a75c2bc85c8eda2928ec73b13809416658f949d2b55fa24448c08b1 deleted: sha256:2d9c829ae3f7ff3e148e5c7c3a1cf378b0f90b79035e2fe9a8d78c63ccde4c89 deleted: sha256:b1ae7168c6f3e061aa3943740ec3ceaf8e582dc65feab31d2b56d464a5062d59 deleted: sha256:4a495dbc04bd205c728297a08cf203988e91caeafe4b21fcad94c893a53d96dc deleted: sha256:3b10514a95bec77489a57d6e2fbfddb7ddfdb643907470ce5de0f1b05c603706 Total reclaimed space: 887.3MB
参考資料
https://docs.docker.com/engine/reference/commandline/container_commit/
https://docs.docker.com/engine/reference/commandline/container_export/
https://docs.docker.com/engine/reference/commandline/image_import/
https://docs.docker.com/engine/reference/commandline/image_save/
https://docs.docker.com/engine/reference/commandline/image_load/
https://docs.docker.com/engine/reference/commandline/image_prune/