docker - 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 :
- Creating the container with :
docker run --name opencascade-build -it ubuntu:latest bash
- Copying the C++ library mirror so i build it on the container :
docker cp opencascade-dev-mirror [my-container-id]:/home
- After building my library i did :
sudo docker commit --author "Tawfik" --message "opencascade-build" [my-container-id] tawfik741/opencascade-build:amd64
- and pushed it to a private repo with :
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 :
- I ran the docker container from the image with :
docker run -it tawfik741/opencascade-build:amd64 /bin/bash
- I updated the container then ran :
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 .
解决方案
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.
推荐阅读
- c# - 剃须刀组件的源生成器不工作
- html - Bootstrap 4.5.3 工具提示放置“自动左”不起作用
- reactjs - map 不是 reactJS 中的函数
- .net - 需要抬高的应用
- angular - 使用 Angular cli 禁用监视 node_modules
- delphi - Delphi 从 THTTPRIO 获取 cookie
- postgresql - pg_basebackup(复制)后无法启动 Postgresql 12
- apache - apache:隐藏目录重定向到 403 而不是 404
- heroku - 应用程序部署时,heroku 中出现“应用程序错误”
- vue.js - Vuetify V-File-input 与 append-outer-icon