Docker: opposite of docker import

Viewed 84

An image created with docker import fails to run, because a necessary file is missing.

I am attempting to debug what is in the image and what is missing.

What I have tried

  • docker save creates a tarball, but it is not a simple tarball with files but all kind of metadata
  • docker export requires a running container.

Do I have any other alternatives?

2 Answers

If the image has a working shell, use that to debug.

docker run -ti BROKEN_IMAGE sh

If a shell doesn't work, export the image contents and you will have a tar file you can extract somewhere and inspect.

CID=$(docker create BROKEN_IMAGE)
docker export $CID | tar -tvf -

Detail

The source file/data for a docker import should be a tar file of the plan image contents. This data can be viewed or extracted somewhere with the tar command:

$ CID=$(docker create busybox)
$ docker export $CID > myimage.tar
$ tar -tvf myimage.tar
-rwxr-xr-x  0 0      0           0 28 Nov 01:03 .dockerenv
drwxr-xr-x  0 0      0           0  1 Nov 22:58 bin/
-rwxr-xr-x  0 0      0     1049688  1 Nov 22:58 bin/[
-rwxr-xr-x  0 0      0           0  1 Nov 22:58 bin/[[ link to bin/[
-rwxr-xr-x  0 0      0           0  1 Nov 22:58 bin/acpid link to bin/[
...

If the file/data is from a docker save there are additional layers to cater for the image metadata and layers.

$ docker save busybox | tar -tvf -
drwxr-xr-x  0 0      0           0  3 Nov 22:39 036a82c6d65f2fa43a13599661490be3fca1c3d6790814668d4e8c0213153b12/
-rw-r--r--  0 0      0           3  3 Nov 22:39 036a82c6d65f2fa43a13599661490be3fca1c3d6790814668d4e8c0213153b12/VERSION
-rw-r--r--  0 0      0        1174  3 Nov 22:39 036a82c6d65f2fa43a13599661490be3fca1c3d6790814668d4e8c0213153b12/json
-rw-r--r--  0 0      0     1337856  3 Nov 22:39 036a82c6d65f2fa43a13599661490be3fca1c3d6790814668d4e8c0213153b12/layer.tar
-rw-r--r--  0 0      0        1497  3 Nov 22:39 6ad733544a6317992a6fac4eb19fe1df577d4dec7529efec28a5bd0edad0fd30.json
-rw-r--r--  0 0      0         203  1 Jan  1970 manifest.json
-rw-r--r--  0 0      0          90  1 Jan  1970 repositories

The LAYER_ID/layer.tar file(s) contain each layer contents which would need to be extracted in the order of the Layers array in manifest.json.

$ cat manifest.json  | jq
[
  {
    "Config": "6ad733544a6317992a6fac4eb19fe1df577d4dec7529efec28a5bd0edad0fd30.json",
    "RepoTags": [
      "busybox:latest"
    ],
    "Layers": [
      "036a82c6d65f2fa43a13599661490be3fca1c3d6790814668d4e8c0213153b12/layer.tar"
    ]
  }
]
Related