5.13. Exporting and importing containers
You can use the podman export command to export the file system of a running container to a tarball on your local machine. For example, if you have a large container that you use infrequently or one that you want to save a snapshot of in order to revert back to it later, you can use the podman export command to export a current snapshot of your running container into a tarball.
You can use the podman import command to import a tarball and save it as a filesystem image. Then you can run this filesystem image or you can use it as a layer for other images.
Prerequisites
-
The
container-toolsmeta-package is installed.
Procedure
Run the
myubicontainer based on theregistry.access.redhat.com/ubi10/ubiimage:$ podman run -dt --name=myubi registry.access.redhat.com/10/ubiOptional: List all containers:
$ podman ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES a6a6d4896142 registry.access.redhat.com/10:latest /bin/bash 7 seconds ago Up 7 seconds ago myubiAttach to the
myubicontainer:$ podman attach myubiCreate a file named
testfile:[root@a6a6d4896142 /]# echo "hello" > testfile-
Detach from the container with
CTRL+pandCTRL+q. Export the file system of the
myubias amyubi-container.taron the local machine:$ podman export -o myubi.tar a6a6d4896142Optional: List the current directory content:
$ ls -l -rw-r--r--. 1 user user 210885120 Apr 6 10:50 myubi-container.tar ...Optional: Create a
myubi-containerdirectory, extract all files from themyubi-container.tararchive. List a content of themyubi-directoryin a tree-like format:$ mkdir myubi-container $ tar -xf myubi-container.tar -C myubi-container $ tree -L 1 myubi-container ├── bin -> usr/bin ├── boot ├── dev ├── etc ├── home ├── lib -> usr/lib ├── lib64 -> usr/lib64 ├── lost+found ├── media ├── mnt ├── opt ├── proc ├── root ├── run ├── sbin -> usr/sbin ├── srv ├── sys ├── testfile ├── tmp ├── usr └── var 20 directories, 1 fileYou can see that the
myubi-container.tarcontains the container file system.Import the
myubi.tarand saves it as a filesystem image:$ podman import myubi.tar myubi-imported Getting image source signatures Copying blob 277cab30fe96 done Copying config c296689a17 done Writing manifest to image destination Storing signatures c296689a17da2f33bf9d16071911636d7ce4d63f329741db679c3f41537e7cbfList all images:
$ podman images REPOSITORY TAG IMAGE ID CREATED SIZE docker.io/library/myubi-imported latest c296689a17da 51 seconds ago 211 MBDisplay the content of the
testfilefile:$ podman run -it --name=myubi-imported myubi-imported cat testfile helloFor more information, see the
podman-export (1)andpodman-import(1)man pages on your system.