If you want to “flatten” an image and avoid the history which has multiple layers, docker export and import is the best way to do that.
docker save – docker save will indeed produce a tarball, but with all parent layers, and all tags + versions.
docker export – docker export does also produce a tarball, but without any layer/history.
However, once those tarballs are produced, load/import are there to:
docker import – docker import creates one image from one tarball which is not even an image (just a filesystem you want to import as an image). Create an empty filesystem image and import the contents of the tarball
docker load – docker load creates potentially multiple images from a tarred repository (since docker save can save multiple images in a tarball). Loads a tarred repository from a file or the standard input stream
[CODE]$ docker run -it ubuntu
$ cd /opt/
root@20a8011f2e65:/opt# touch DevOpsSchool.com
root@20a8011f2e65:/opt# ls
DevOpsSchool.com
CNTRL + P + Q
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
20a8011f2e65 ubuntu “/bin/bash” 24 seconds ago Up 23 seconds thirsty_wilson
$ docker export -o ubuntu-devops.tar 20a8011f2e65
$ docker help import
Usage: docker import [OPTIONS] file|URL|- [REPOSITORY[:TAG]]
Import the contents from a tarball to create a filesystem image
Options:
-c, –change list Apply Dockerfile instruction to the created image
–help Print usage
-m, –message string Set commit message for imported image
$ docker import -m”ubuntu+devopsschool” ubuntu-devops. tar
sha256:c9b6e68b24325d86c511cd45071e69cacd185835b427c83f1cecf7e2e001b13e
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
c9b6e68b2432 4 seconds ago 69.8MB
$ docker tag c9b6e68b2432 ubuntu-devopsschool.com
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
ubuntu-devopsschool.com latest c9b6e68b2432 25 seconds ago 69.8MB
$ docker run -itd ubuntu-devopsschool.com ls /opt
04ed9676981d943f85de58b9885f0347f4ed11c96d97546d484173b7fcd48101
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
20a8011f2e65 ubuntu “/bin/bash” 2 minutes ago Up 2 minutes
$ docker exec 20a8011f2e65 ls /opt
DevOpsSchool.com
$ docker history ubuntu-devopsschool.com
IMAGE CREATED CREATED BY SIZE COMMENT
c9b6e68b2432 About a minute ago 69.8MB ubuntu+devopsschool[/CODE]
Docker Tutorials Fundamental To Advanced-2021 Crash Course:- https://bit.ly/3hOIbTB
- Laravel breeze vs laravel fortify comparison - December 17, 2024
- How to Choose Wireless Access Points for Office - December 13, 2024
- Online Real Estate Courses: Navigating the Shift to Digital Education - December 13, 2024