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-tools meta-package is installed.

Procedure

  1. Run the myubi container-based on the registry.access.redhat.com/ubi10/ubi image:
    $ podman run -dt --name=myubi registry.access.redhat.com/10/ubi
  2. Optional: 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          myubi
  3. Attach to the myubi container:
    $ podman attach myubi
  4. Create a file named testfile:
    [root@a6a6d4896142 /]# echo "hello" > testfile
  5. Detach from the container with CTRL+p and CTRL+q.
  6. Export the file system of the myubi as a myubi-container.tar on the local machine:
    $ podman export -o myubi.tar a6a6d4896142
  7. Optional: List the current directory content:
    $ ls -l
    -rw-r--r--. 1 user user 210885120 Apr  6 10:50 myubi-container.tar
    ...
  8. Optional: Create a myubi-container directory, extract all files from the myubi-container.tar archive. List a content of the myubi-directory in 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 file

    You can see that the myubi-container.tar contains the container file system.

  9. Import the myubi.tar and 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
    c296689a17da2f33bf9d16071911636d7ce4d63f329741db679c3f41537e7cbf
  10. List all images:
    $ podman images
    REPOSITORY                              TAG     IMAGE ID      CREATED         SIZE
    docker.io/library/myubi-imported       latest  c296689a17da  51 seconds ago  211 MB
  11. Display the content of the testfile file:
    $ podman run -it --name=myubi-imported myubi-imported cat testfile
    hello

    You can use the podman export command 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 import command 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) and podman-import(1) man pages on your system.