首页 > 解决方案 > what is the correct way to update a docker image

问题描述

I created an ubuntu docker container, copied a mirror of a c++ library (sized 1.2 gb) I'll be using on it (on the docker container's home directory), built it on it and forgot to remove the mirror before creating the image and pushing to docker hub.

I then tried to re-run the container from the image to remove the c++ mirror so i can commit the new image , but the new image didn't downsize for a reason i ignore . After i run docker images i still have :

REPOSITORY                    TAG                 IMAGE ID            CREATED             SIZE
tawfik741/opencascade-build   amd64               74f333aa7293        16 minutes ago      1.79GB

The commands i ran are :

docker run --name opencascade-build -it ubuntu:latest bash
docker cp opencascade-dev-mirror [my-container-id]:/home
sudo docker commit --author "Tawfik" --message "opencascade-build" [my-container-id] tawfik741/opencascade-build:amd64
docker push tawfik741/opencascade-build:amd64 

after figuring up that i forgot to remove that opencascade-dev-mirror from the container i decided to run the container , remove it , and save the new image , i tried in to save a new image but it's exactly the same size as the old one :

docker run -it tawfik741/opencascade-build:amd64 /bin/bash
docker commit --author "Onboard SARL" --message "opencascade-build" [my-container's id] tawfik741/opencascade-build:correction-amd64-correction

but the tawfik741/opencascade-build:amd64-correction has the same size as the tawfik741/opencascade-build:amd64 image .

标签: docker

解决方案


You cannot edit, modify, or update an image once you've created it.

You can create a new image based on an existing image. The way Docker works internally, the new image always contains the entire old image, plus a description of what changed from the old image. Doing this never makes the new image smaller, only larger.

You need to start over and create a new image starting from the original base image. If you use the standard docker build command and Dockerfile system, it should be enough to delete the COPY line that adds the large file to the image and rebuild. If you're using docker commit, you need to completely start over and hope you repeat the same manual commands in the same way; even if you're trying to "iterate rapidly" you'll be much better off switching to a Dockerfile.


推荐阅读