How to remove all intermediate docker images that were created using the docker commit
command, leaving only the very first and the very last docker image? When trying to remove, "image has dependent child images" is displayed - tell me how to fix this?
Should I save changes in a docker container using the docker commit
command or is there a more convenient/suitable practice for this purpose?
I describe my actions in chronological order:
Downloading the docker image 'tensorflow/tensorflow' via the GUI in the Docker Desktop application. Then all other actions were performed on the command line.
Running the container:
docker run -it IMAGE_ID /bin/bash
Saving changes at all stages of work using the
docker commit
command:
// did something inside a running container...
docker commit --message "comment 1" CONTAINER_ID test_repo_name_1:test_tag_name_1
// did something inside a running container...
docker commit --message "comment 2" CONTAINER_ID test_repo_name_2:test_tag_name_2
// did something inside a running container...
docker commit --message "comment 3" CONTAINER_ID test_repo_name_3:test_tag_name_3
// did something inside a running container...
docker commit --message "comment 4" CONTAINER_ID test_repo_name_4:test_tag_name_4
All commits (and also running the container) were done in the same docker context "desktop-linux":
roman@roman-lenovo-ideapad:~/path/to/work_directory$ docker context listNAME TYPE DESCRIPTION DOCKER ENDPOINTdefault moby Current DOCKER_HOST based configuration unix:///var/run/docker.sockdesktop-linux * moby Docker Desktop unix:///home/roman/.docker/desktop/docker.sock
Stopping a container:
docker stop CONTAINER_ID
Removing a container:
docker rm CONTAINER_ID
Viewing the list of docker images:
roman@roman-lenovo-ideapad:~/path/to/work_directory$ docker image list --allREPOSITORY TAG IMAGE ID CREATED SIZEtest_repo_name_4 test_tag_name_4 1751814a0b9c 3 days ago 4.15GBtest_repo_name_3 test_tag_name_3 1e036ed78145 5 days ago 3.25GBtest_repo_name_2 test_tag_name_2 4f4ee9469091 4 weeks ago 2.42GBtest_repo_name_1 test_tag_name_1 9fa17c3eada6 5 weeks ago 1.9GBtensorflow/tensorflow latest c157882405b4 6 weeks ago 1.84GB
- Attempt to delete images 9fa17c3eada6, 4f4ee9469091, 1e036ed78145
docker rmi 9fa17c3eada6 --force
Error response from daemon : conflict: unable to delete 9fa17c3eada6 (cannot be forced) - image has dependent child images
I got a similar output for "docker rmi 4f4ee9469091 --force
" and "docker rmi 1e036ed78145 --force
"
- Attempt to delete images 9fa17c3eada6, 4f4ee9469091, 1e036ed78145
docker rmi test_repo_name_1:test_tag_name_1 --force
docker rmi test_repo_name_2:test_tag_name_2 --force
docker rmi test_repo_name_3:test_tag_name_3 --force
docker image prune
docker system prune
Command "docker image list --all
" still shows that images 9fa17c3eada6, 4f4ee9469091, 1e036ed78145 exist
roman@roman-lenovo-ideapad:~/path/to/work_directory$ docker image list --allREPOSITORY TAG IMAGE ID CREATED SIZEtest_repo_name_4 test_tag_name_4 1751814a0b9c 3 days ago 4.15GB<none> <none> 1e036ed78145 6 days ago 3.25GB<none> <none> 4f4ee9469091 4 weeks ago 2.42GB<none> <none> 9fa17c3eada6 5 weeks ago 1.9GBtensorflow/tensorflow latest c157882405b4 6 weeks ago 1.84GB
Now "none" appears instead of "test_repo_name" (and also instead of "test_tag_name")
Then go to point 7 and get the same result - "image has dependent child images"
Below are the conditions under which the testing was conducted
Contents of the /etc/docker/daemon.json
file on the host:
{"default-runtime": "nvidia","dns": ["192.168.1.1","8.8.8.8" ],"exec-opts": ["native.cgroupdriver=cgroupfs" ],"runtimes": {"nvidia": {"args": [],"path": "nvidia-container-runtime" } }}
Contents of the ~/.config/docker/daemon.json
file on the host:
{"runtimes": {"nvidia": {"args": [],"path": "nvidia-container-runtime" } }}
Output of the uname -a
command on the host:
Linux roman-lenovo-ideapad 6.8.0-40-generic #40~22.04.3-Ubuntu SMP PREEMPT_DYNAMIC Tue Jul 30 17:30:19 UTC 2 x86_64 x86_64 x86_64 GNU/Linux
Output of the lsb_release -a
command on the host:
LSB Version: core-11.1.0ubuntu4-noarch:security-11.1.0ubuntu4-noarchDistributor ID: UbuntuDescription: Ubuntu 22.04.4 LTSRelease: 22.04Codename: jammy