3

I wanna save a docker image to a rootfs format(like a dir consisting of /etc /var ...), which is just like what docker export does. Also docker save cannot meet my need too because it saves layers of the image other than the dir they mount together. But I do not want to use docker export because it only works when a container using this image is running. Now I have an image list containing about 1000 entries, how can I save every image to rootfs without starting a container first on each of them?

flyingrose
  • 97
  • 1
  • 10
  • 3
    Just a thought: iterate through your images, use `docker create ...` to create a container (with `create` it won't start), then use `docker export ...` and finally cleanup with `docker rm ...`. – tgogos Dec 11 '18 at 13:33
  • 1
    @tgogos thx a lot. I thought `docker export` would not work on stopped containers. But I tried and found it worked! – flyingrose Dec 11 '18 at 14:02

3 Answers3

2

Quoting @tgogos comment:

iterate through your images, use docker create ... to create a container (with create it won't start), then use docker export ... and finally cleanup with docker rm ...

lucasvc
  • 624
  • 1
  • 9
  • 31
1

To expand on @lucasvc's answer, here is a one-liner to do it:

docker export $(docker create <image id>) --output="latest.tar"
sashoalm
  • 63,456
  • 96
  • 348
  • 677
0

I just open sourced undocker, which can convert docker image layers to a rootfs tarball:

$ skopeo copy docker://docker.io/busybox:latest docker-archive:busybox.tar
$ undocker busybox.tar - | tar -tv
drwxr-xr-x 0/0               0 2021-05-17 22:07 bin/
-rwxr-xr-x 0/0         1149184 2021-05-17 22:07 bin/[
hrwxr-xr-x 0/0               0 2021-05-17 22:07 bin/[[ link to bin/[
hrwxr-xr-x 0/0               0 2021-05-17 22:07 bin/acpid link to bin/[
hrwxr-xr-x 0/0               0 2021-05-17 22:07 bin/add-shell link to bin/[
hrwxr-xr-x 0/0               0 2021-05-17 22:07 bin/addgroup link to bin/[
hrwxr-xr-x 0/0               0 2021-05-17 22:07 bin/adduser link to bin/[
hrwxr-xr-x 0/0               0 2021-05-17 22:07 bin/adjtimex link to bin/[
hrwxr-xr-x 0/0               0 2021-05-17 22:07 bin/ar link to bin/[
hrwxr-xr-x 0/0               0 2021-05-17 22:07 bin/arch link to bin/[
...
Motiejus Jakštys
  • 2,337
  • 2
  • 21
  • 24