skip to Main Content

I build an image from a dockerfile, now I found that its size is 450 MB. But I wanted to reduce the size without deleting it or making changes in dockerfile. How can I do that ?

I didn’t find any solution.

2

Answers


  1. No. This is not possible without making changes in the Dockerfile. That would be peculiar, as Docker would already have done that in the first place, when building the image.

    Docker already uses layering, which means that the space an image takes up, is the space the total image actually consumes.

    So the only thing you can do is find out whether the images your image is based on, are bloated, and then possibly select another one.

    • For OS images like Debian or Ubuntu, there are slim variants, which are a little bit stripped down. I don’t know the exact details, but they should be smaller in size.
    • Some Docker images of software packages are very large, like the image for Azure CLI (mcr.microsoft.com/azure-cli; more than 1 GB). The question is whether you need all of the stuff within it.
    Login or Signup to reply.
  2. You cannot reduce image size, but you can find ways to get base images with less MB.

    For example, always check the alpine images. You can check what is alpine here

    For example, a node js image base has a size of about 600MB, while same image in an alpine format has about 60MB.

    You can set this kind of things in the FROM tag in the Dockerfile. For example:

    FROM node:14.17.6-alpine3.11

    Hope it helps.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search