brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: docker export -o saves a container filesystem as a tar file

Docker
~/tips/tip-docker-export-output

docker export red_panda > latest.tar

Writes the full filesystem of a container, running or stopped, to a tar file.

Sometimes I want the files of a container, not an image I can run. docker export gives you the whole filesystem as one tar archive.

The command writes a tar of the container’s filesystem to standard output, or to a file with -o (long form --output). The reference shows that these two lines do the same thing:

docker export red_panda > latest.tar
docker export --output="latest.tar" red_panda

You can then look inside without starting anything:

tar -tf latest.tar | head

It works on a stopped container too, so it is a decent way to grab config files or a program from a container that no longer starts.

If you think of this as a backup, know that it does not export the contents of volumes. The docs say that if a volume is mounted over a directory, the export contains the original directory underneath and not the volume’s data. For a database or an appdata folder that means the archive is nearly empty where it counts. Back up volumes separately (see the docs on backing up volumes), and treat docker export as a way to inspect or copy the container’s own files. It is also different from docker save, which keeps the image layers and metadata.

Further reading: docker container export

More Docker tips ONBUILD RUN /usr/local/bin/python-build --dir /app/src SHELL ["/bin/bash", "-c"] docker commit <container> myname/testimage:version3 docker import /path/to/exampleimage.tgz docker compose events All Docker tips (192) All topics

Link