I am trying
docker rmi c565603bc87f
Error:
Error response from daemon: conflict: unable to delete c565603bc87f (ca
When i want to remove some unused image with name "<none>"
in docker i face with the problem unable to delete a354bbc7c9b7 (cannot be forced) - image has dependent child images
.So for solving this problem:
sudo docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
01ee1276bbe0 lizard:1 "/bin/sh -c 'java ..." About an hour ago Exited (1) About an hour ago objective_lewin
49d73d8fb023 javaapp:latest "/usr/bin/java -ja..." 19 hours ago Up 19 hours 0.0.0.0:8091->8091/tcp pedantic_bell
405fd452c788 javaapp:latest "/usr/bin/java -ja..." 19 hours ago Created infallible_varahamihira
532257a8b705 javaapp:latest "/usr/bin/java -ja..." 19 hours ago Created demo-default
9807158b3fd5 javaapp:latest "/usr/bin/java -ja..." 19 hours ago Created xenodochial_kilby
474930241afa jenkins "/bin/tini -- /usr..." 13 days ago Up 4 days 0.0.0.0:8080->8080/tcp, 0.0.0.0:50000->50000/tcp myjenkins
563d8c34682f mysql/mysql-server:latest "/entrypoint.sh my..." 3 weeks ago Up 4 days (healthy) 0.0.0.0:3306->3306/tcp, 33060/tcp mymysql
b4ca73d45d20 phpmyadmin/phpmyadmin "/run.sh phpmyadmin" 4 weeks ago Exited (0) 3 weeks ago phpmyadmin
you can see that i have several Images with name javaapp:latest and different container name. So, i killed and remove all container of "javaapp:latest" container with:
sudo docker stop "containerName"
sudo docker rm "containrName"
Then
sudo docker rmi -f "imageId"
So i can remove all the images with name "<none>"
goodluck
I also got this issue, I could resolve issue with below commands. this may be cause, the image's container is running or exit so before remove image you need to remove container
docker ps -a -f status=exited : this command shows all the exited containers so then copy container Id and then run below commands to remove container
docker rm #containerId : this command remove container this may be issue that mention "image has dependent child images"
Then try to remove image with below command
docker rmi #ImageId
Image Layer: Repositories are often referred to as images or container images, but actually they are made up of one or more layers. Image layers in a repository are connected together in a parent-child relationship. Each image layer represents changes between itself and the parent layer.
The docker building pattern uses inheritance. It means the version i
depends on version i-1
. So, we must delete the version i+1
to be able to delete version i
. This is a simple dependency.
If you wanna delete all images except the last one (the most updated) and the first (base) then we can export the last (the most updated one) using docker save
command as below.
docker save -o <output_file> <your_image-id> | gzip <output_file>.tgz
Then, now, delete all the images using image-id as below.
docker rm -f <image-id i> | docker rm -f <image i-1> | docker rm -f <image-id i-2> ... <docker rm -f <image-id i-k> # where i-k = 1
Now, load your saved tgz image as below.
gzip -c <output_file.tgz> | docker load
see the image-id of your loaded image using docker ps -q. It doesn't have tag and name. You can simply update tag and name as done below.
docker tag <image_id> group_name/name:tag
Here's a script to remove an image and all the images that depend on it.
#!/bin/bash
if [[ $# -lt 1 ]]; then
echo must supply image to remove;
exit 1;
fi;
get_image_children ()
{
ret=()
for i in $(docker image ls -a --no-trunc -q); do
#>&2 echo processing image "$i";
#>&2 echo parent is $(docker image inspect --format '{{.Parent}}' "$i")
if [[ "$(docker image inspect --format '{{.Parent}}' "$i")" == "$1" ]]; then
ret+=("$i");
fi;
done;
echo "${ret[@]}";
}
realid=$(docker image inspect --format '{{.Id}}' "$1")
if [[ -z "$realid" ]]; then
echo "$1 is not a valid image.";
exit 2;
fi;
images_to_remove=("$realid");
images_to_process=("$realid");
while [[ "${#images_to_process[@]}" -gt 0 ]]; do
children_to_process=();
for i in "${!images_to_process[@]}"; do
children=$(get_image_children "${images_to_process[$i]}");
if [[ ! -z "$children" ]]; then
# allow word splitting on the children.
children_to_process+=($children);
fi;
done;
if [[ "${#children_to_process[@]}" -gt 0 ]]; then
images_to_process=("${children_to_process[@]}");
images_to_remove+=("${children_to_process[@]}");
else
#no images have any children. We're done creating the graph.
break;
fi;
done;
echo images_to_remove = "$(printf %s\n "${images_to_remove[@]}")";
indices=(${!images_to_remove[@]});
for ((i="${#indices[@]}" - 1; i >= 0; --i)) ; do
image_to_remove="${images_to_remove[indices[i]]}"
if [[ "${image_to_remove:0:7}" == "sha256:" ]]; then
image_to_remove="${image_to_remove:7}";
fi
echo removing image "$image_to_remove";
docker rmi "$image_to_remove";
done
In some cases (like in my case) you may be trying to delete an image by specifying the image id that has multiple tags that you don't realize exist, some of which may be used by other images. In which case, you may not want to remove the image.
If you have a case of redundant tags as described here, instead of docker rmi <image_id>
use docker rmi <repo:tag>
on the redundant tag you wish to remove.
I had this issue and none of the short answers here worked, even in the page mentioned by @tudor above. I thought I would share here how I got rid of the images. I came up with the idea that dependent images must be >= the size of the parent image, which helps identify it so we can remove it.
I listed the images in size order to see if I could spot any correlations:
docker images --format '{{.Size}}\t{{.Repository}}\t{{.Tag}}\t{{.ID}}' | sort -h -r | column -t
What this does, is use some special formatting from docker to position the image size column first, then run a human readable sort in reverse order. Then I restore the easy-to-read columns.
Then I looked at the <none>
containers, and matched the first one in the list with a similar size. I performed a simple docker rmi <image:tag>
on that image and all the <none>
child images went with it.
The problem image with all the child images was actually the damn myrepo/getstarted-lab
image I used when I first started playing with docker. It was because I had created a new image from the first test image which created the chain.
Hopefully that helps someone else at some point.