Search notes:

docker export

docker export exports a container's filesystem as a tar archive.
By default, the content of the tar archive is written to stdout.
The command line option -o (or --output) can be used to specify the name of a tar file.

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!
  …

Extracting the filesystem to a local directory

$ containername=…
$ destdir=/tmp/exported-container
$ mkdir $destdir
$ docker export $containername | tar x -C $destdir
tar: dev/full: Cannot mknod: Operation not permitted
tar: dev/null: Cannot mknod: Operation not permitted
tar: dev/ptmx: Cannot mknod: Operation not permitted
tar: dev/random: Cannot mknod: Operation not permitted
tar: dev/tty: Cannot mknod: Operation not permitted
tar: dev/tty0: Cannot mknod: Operation not permitted
tar: dev/urandom: Cannot mknod: Operation not permitted
tar: dev/zero: Cannot mknod: Operation not permitted
tar: Exiting with failure status due to previous errors
$ tree $destdir

See also

Docker commands such as docker save

Index

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/developm...', 1759383858, '216.73.216.42', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/development/tools/Docker/commands/export(94): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78