Simple example
Create a container (named hello-world-container
) from the image hello-world
:
$ docker create --name hello-world-container hello-world
…
Use docker export
on the container name and pipe the result to tar tv
which verbosely (i. e. with file size etc.) lists the content of the «tar file»:
$ docker export hello-world-container | tar tv
-rwxr-xr-x root/0 0 2024-02-12 21:20 .env
drwxr-xr-x root/0 0 2024-02-12 21:20 dev/
-rwxr-xr-x root/0 0 2024-02-12 21:20 dev/console
drwxr-xr-x root/0 0 2024-02-12 21:20 dev/pts/
drwxr-xr-x root/0 0 2024-02-12 21:20 dev/shm/
drwxr-xr-x root/0 0 2024-02-12 21:20 etc/
-rwxr-xr-x root/0 0 2024-02-12 21:20 etc/hostname
-rwxr-xr-x root/0 0 2024-02-12 21:20 etc/hosts
lrwxrwxrwx root/0 0 2024-02-12 21:20 etc/mtab -> /proc/mounts
-rwxr-xr-x root/0 0 2024-02-12 21:20 etc/resolv.conf
-rwxr-xr-x root/0 13256 2023-12-15 23:04 hello
drwxr-xr-x root/0 0 2024-02-12 21:20 proc/
drwxr-xr-x root/0 0 2024-02-12 21:20 sys/
In this container, hello
is the only file with non-zero bytes. Extract it from the container:
$ docker hello-world-container | tar x hello
We can now execute hello
locally rather than in the container:
$ ./hello
Hello from Docker!
…