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 import creates an image from a tarball of a filesystem

Docker
~/tips/tip-docker-import-tarball-image

docker import /path/to/exampleimage.tgz

Builds a fresh image from a root filesystem archive, from a file, a URL or stdin.

Most of the time I load images with docker load. docker import is the other one, and it does something different: it takes a plain filesystem archive and makes an image out of it.

docker import /path/to/exampleimage.tgz
cat exampleimage.tgz | docker import - exampleimagelocal:new
docker import --change "ENV DEBUG=true" ./rootfs.tgz exampleimagedir

The docs describe it as importing the contents from a tarball to create a filesystem image. The source can be a file, a URL or - for stdin, and the supported archives are .tar, .tar.gz, .tgz, .bzip, .tar.xz and .txz. The second argument is the repository and tag. Without it you get an untagged image.

You can set --change more than once to add Dockerfile instructions. That is how you give the image a CMD or ENV, because a bare tarball carries no configuration. The docs say the list is limited to metadata changes, so not every instruction works.

Caveats from the docs: when you import a directory, you need to keep the file ownership, especially root ownership, while you archive it with tar. And there is --platform for multi-platform daemons, otherwise the daemon’s native platform is used.

A good pairing is docker export, which writes a container’s filesystem to a tar. Import that archive again and you get an image of that filesystem. I’d keep the original image around until I have checked the result.

Further reading: docker image import

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

Link