Export and import containers
To easily transfer filesystems between different host environments, you can export and import Red Hat Enterprise Linux containers. Packaging your container into an archive(tar file) helps you back up essential data, share configurations with your team, and seamlessly migrate isolated workloads.
Before you begin
- 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/ubi -
Optional: List all containers:
$ podman ps -aCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES a6a6d4896142 registry.access.redhat.com/10:latest /bin/bash 7 seconds ago Up 7 seconds ago myubi -
Attach to the
myubicontainer:$ podman attach myubi -
Create 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 a6a6d4896142 -
Optional: 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-importedGetting image source signatures Copying blob 277cab30fe96 done Copying config c296689a17 done Writing manifest to image destination Storing signatures c296689a17da2f33bf9d16071911636d7ce4d63f329741db679c3f41537e7cbf -
List all images:
$ podman imagesREPOSITORY TAG IMAGE ID CREATED SIZE docker.io/library/myubi-imported latest c296689a17da 51 seconds ago 211 MB -
Display the content of the
testfilefile:$ podman run -it --name=myubi-imported myubi-imported cat testfilehelloYou can use the
podman exportcommand to export the file system of a running container to a tar file 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 to revert to it later.Also, you can use the
podman importcommand to import a tar file 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.For more information, see the
podman-export (1)andpodman-import(1)man pages on your system.