Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

132
Views
size of saved docker images for base versus derived

In an empty directory, I have run a sequence of commands shown in the following terminal capture:

$ echo -e "from alpine" > Dockerfile
$ docker build --tag alpine .
Sending build context to Docker daemon  2.048kB
Step 1/1 : from alpine
 ---> c059bfaa849c
Successfully built c059bfaa849c
Successfully tagged alpine:latest
$ docker image save -o alpine.tar alpine
$ echo -e "from alpine \nrun apk add --no-cache tini" > Dockerfile
$ docker build --tag tini .
Sending build context to Docker daemon  11.76MB
Step 1/2 : from alpine
 ---> c059bfaa849c
Step 2/2 : run apk add --no-cache tini
 ---> Using cache
 ---> e50ce83132ec
Successfully built e50ce83132ec
Successfully tagged tini:latest
$ docker image save -o tini.tar tini
$ ls -sh *.tar
 12M alpine.tar  5.7M tini.tar

As expected, the image labeled tini builds a further layer above the one shared with alpine. However, the resulting saved file for the former image is smaller than that for the latter.

Expected is that the image saved in the former file is a superset of the latter, and therefore larger.

Why is this expectation not confirmed by observation?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Best guess is something else was tagged alpine on your host when you did the build, and between the two commands, something pulled the correct alpine image down. But rather than guessing, you have the file to tell you exactly what was in that first alpine image. Extract the tar, review the manifest, and review the config the manifest points to. Here's an example with whatever old version of alpine:latest I happened to have on my machine:

$ cat manifest.json | jq .
[
  {
    "Config": "45683da4f97c23d92b878d2ad15eb66e94c9cab368e54797bcd4a4b20c915815.json",
    "RepoTags": [
      "test-alpine:latest"
    ],
    "Layers": [
      "4833c0e9afedb6022373ef7da2cee392c97a5f4438e7f52a1f940903db618437/layer.tar"
    ]
  }
]

$ cat 45683da4f97c23d92b878d2ad15eb66e94c9cab368e54797bcd4a4b20c915815.json | jq .
{
  "architecture": "amd64",
  "config": {
    "Env": [
      "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
    ],
    "Cmd": [
      "/bin/sh"
    ],
    "OnBuild": null
  },
  "created": "2021-08-27T17:19:45.758611523Z",
  "history": [
    {
      "created": "2021-08-27T17:19:45.553092363Z",
      "created_by": "/bin/sh -c #(nop) ADD file:aad4290d27580cc1a094ffaf98c3ca2fc5d699fe695dfb8e6e9fac20f1129450 in / "
    },
    {
      "created": "2021-08-27T17:19:45.758611523Z",
      "created_by": "/bin/sh -c #(nop)  CMD [\"/bin/sh\"]",
      "empty_layer": true
    }
  ],
  "os": "linux",
  "rootfs": {
    "type": "layers",
    "diff_ids": [
      "sha256:e2eb06d8af8218cfec8210147357a68b7e13f7c485b991c288c2d01dc228bb68"
    ]
  }
}

When you compare the two images, if they were built from the same alpine base, they will have the same initial set of layers. In your case, they almost certainly won't.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!