Delete the old image after docker commit the new image

1. Purpose

    Add some files on the basis of the old image, commit a new image after modification, and then delete the previous old image

2. Implementation

    2.1 Use Dockerfile to create a new one

    2.2 Use the commit command, this article uses the second

3. Steps

    Suppose the original image is: nginx:latest

    3.1 Boot image

docker run -it nginx:latest /bin/bash

    3.2 Open another Shell window

    612f701cc061 is CONTAINER ID

docker commit 612f701cc061 nginx2

    3.3 View image

    You can see that the two IMAGE IDs are not the same,

    New image ID fff815b9c91f

    Old Image ID b175e7467d66

    3.4 Delete mirror

    First stop the image started above, delete the relevant container, and then delete the old image, but it is not successful, the image has dependencies

docker rmi b175e7467d66

    Check if there is a dependency, b175e7467d66 is the IMAGE ID 

docker inspect --format='{{.Id}} {{.Parent}}' $(docker images --filter since=b175e7467d66 --quiet)

    There is indeed a commit fff815b9c91f image dependency

    3.5 Save the new image

docker save -o nginx2:latest nginx.tar

    3.6 Delete old and new images

docker rmi fff815b9c91f b175e7467d66

    3.7 load new image

docker load -i ./nginx.tar

    So far, the purpose has been achieved, the relevant webpage

https://stackoverflow.com/questions/42834293/deleting-old-images-in-docker-osx

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324981346&siteId=291194637