Docker说它不能删除镜像,因为一个容器正在运行,但没有容器正在运行



总之:我想删除一个docker镜像,但是如果我这样做,它告诉我不能删除,因为镜像正在被运行的容器使用。但是据我所知,根本没有容器在运行。

详细:我调用docker images -a来查看调用图像。这样我就确定了我想要删除的图像ID,并调用docker image rm {ID},其中{ID}是应该删除的字符串(它适用于其他图像,所以到目前为止我很有信心)。我得到了响应:

来自守护进程的错误响应:冲突:无法删除{ID}(不能强制)-映像正在被运行容器08815cd48523使用(最后的ID似乎随着每次调用而改变)

这个错误似乎很容易理解,但如果我调用docker ps -a,它告诉我,我没有一个容器运行,因此没有容器运行与指定的ID。

某些图像出现此问题。但似乎都与Kubernetes有关。有人知道是什么问题吗?

在评论中听到docker检查一个不可见的容器(我用"removed_for_post"替换了所有我不确定它是否包含敏感数据的部分):

[
{
"Id": "Removed_for_post",
"Created": "2021-10-05T07:04:33.2059908Z",
"Path": "/pause",
"Args": [],
"State": {
"Status": "running",
"Running": true,
"Paused": false,
"Restarting": false,
"OOMKilled": false,
"Dead": false,
"Pid": 3570,
"ExitCode": 0,
"Error": "",
"StartedAt": "2021-10-05T07:04:33.4266642Z",
"FinishedAt": "0001-01-01T00:00:00Z"
},
"Image": "sha256:80d28bedfe5dec59da9ebf8e6260224ac9008ab5c11dbbe16ee3ba3e4439ac2c",
"ResolvConfPath": "/var/lib/docker/containers/ Removed_for_post /resolv.conf",
"HostnamePath": "/var/lib/docker/containers/ Removed_for_post /hostname",
"HostsPath": "/var/lib/docker/containers/ Removed_for_post /hosts",
"LogPath": "/var/lib/docker/containers/ Removed_for_post / Removed_for_post -json.log",
"Name": "/k8s_POD_etcd-docker-desktop_kube-system_ Removed_for_post ",
"RestartCount": 0,
"Driver": "overlay2",
"Platform": "linux",
"MountLabel": "",
"ProcessLabel": "",
"AppArmorProfile": "",
"ExecIDs": null,
"HostConfig": {
"Binds": null,
"ContainerIDFile": "",
"LogConfig": {
"Type": "json-file",
"Config": {}
},
"NetworkMode": "host",
"PortBindings": {},
"RestartPolicy": {
"Name": "",
"MaximumRetryCount": 0
},
"AutoRemove": false,
"VolumeDriver": "",
"VolumesFrom": null,
"CapAdd": null,
"CapDrop": null,
"CgroupnsMode": "host",
"Dns": null,
"DnsOptions": null,
"DnsSearch": null,
"ExtraHosts": null,
"GroupAdd": null,
"IpcMode": "shareable",
"Cgroup": "",
"Links": null,
"OomScoreAdj": -998,
"PidMode": "",
"Privileged": false,
"PublishAllPorts": false,
"ReadonlyRootfs": false,
"SecurityOpt": [
"no-new-privileges"
],
"UTSMode": "",
"UsernsMode": "",
"ShmSize": 67108864,
"Runtime": "runc",
"ConsoleSize": [
0,
0
],
"Isolation": "",
"CpuShares": 2,
"Memory": 0,
"NanoCpus": 0,
"CgroupParent": "/kubepods/kubepods/besteffort/removed_for_Post",
"BlkioWeight": 0,
"BlkioWeightDevice": null,
"BlkioDeviceReadBps": null,
"BlkioDeviceWriteBps": null,
"BlkioDeviceReadIOps": null,
"BlkioDeviceWriteIOps": null,
"CpuPeriod": 0,
"CpuQuota": 0,
"CpuRealtimePeriod": 0,
"CpuRealtimeRuntime": 0,
"CpusetCpus": "",
"CpusetMems": "",
"Devices": null,
"DeviceCgroupRules": null,
"DeviceRequests": null,
"KernelMemory": 0,
"KernelMemoryTCP": 0,
"MemoryReservation": 0,
"MemorySwap": 0,
"MemorySwappiness": null,
"OomKillDisable": false,
"PidsLimit": null,
"Ulimits": null,
"CpuCount": 0,
"CpuPercent": 0,
"IOMaximumIOps": 0,
"IOMaximumBandwidth": 0,
"MaskedPaths": [
"/proc/asound",
"/proc/acpi",
"/proc/kcore",
"/proc/keys",
"/proc/latency_stats",
"/proc/timer_list",
"/proc/timer_stats",
"/proc/sched_debug",
"/proc/scsi",
"/sys/firmware"
],
"ReadonlyPaths": [
"/proc/bus",
"/proc/fs",
"/proc/irq",
"/proc/sys",
"/proc/sysrq-trigger"
]
},
"GraphDriver": {
"Data": {
"LowerDir": "/var/lib/docker/overlay2/ Removed_for_post -init/diff:/var/lib/docker/overlay2/ Removed_for_post /diff",
"MergedDir": "/var/lib/docker/overlay2/Removed_for_post /merged",
"UpperDir": "/var/lib/docker/overlay2/Removed_for_post /diff",
"WorkDir": "/var/lib/docker/overlay2/Removed_for_post /work"
},
"Name": "overlay2"
},
"Mounts": [],
"Config": {
"Hostname": "docker-desktop",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": false,
"AttachStderr": false,
"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": [
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
],
"Cmd": null,
"Image": "k8s.gcr.io/pause:3.2",
"Volumes": null,
"WorkingDir": "/",
"Entrypoint": [
"/pause"
],
"OnBuild": null,
"Labels": {
"annotation.kubeadm.kubernetes.io/etcd.advertise-client-urls": "https://192.168.65.4:2379",
"annotation.kubernetes.io/config.hash": " Removed_for_post ",
"annotation.kubernetes.io/config.seen": "2021-10-05T07:04:32.243805800Z",
"annotation.kubernetes.io/config.source": "file",
"component": "etcd",
"io.kubernetes.container.name": "POD",
"io.kubernetes.docker.type": "podsandbox",
"io.kubernetes.pod.name": "etcd-docker-desktop",
"io.kubernetes.pod.namespace": "kube-system",
"io.kubernetes.pod.uid": "removed for Post",
"tier": "control-plane"
}
},
"NetworkSettings": {
"Bridge": "",
"SandboxID": " Removed_for_post",
"HairpinMode": false,
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"Ports": {},
"SandboxKey": "/var/run/docker/netns/default",
"SecondaryIPAddresses": null,
"SecondaryIPv6Addresses": null,
"EndpointID": "",
"Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"IPAddress": "",
"IPPrefixLen": 0,
"IPv6Gateway": "",
"MacAddress": "",
"Networks": {
"host": {
"IPAMConfig": null,
"Links": null,
"Aliases": null,
"NetworkID": " Removed_for_post ",
"EndpointID": " Removed_for_post ",
"Gateway": "",
"IPAddress": "",
"IPPrefixLen": 0,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"MacAddress": "",
"DriverOpts": null
}
}
}
}
]``

您的容器似乎是由其他工具如docker-compose创建的,因为我猜它是在您的计算机上的本地。

这意味着你不能很容易地用docker rm语句停止它的创建。

EDIT 1 - Kubernetes

  • 您似乎正在使用docker桌面
  • 您的容器似乎是etcd,这是kubernetes主系统的一部分(非常重要):

k8s_POD_etcd-docker-desktop_kube-system_ Removed_for_post

所以,由于它是kubernetes组件的一部分,只有当你不想使用kubernetes时,你才应该删除它。

通过删除kubernetes或etcd pod。

如果是docker-desktop,应该没有问题。

总结,your container is created by a pod which is a resource handled by kubernetes

docker-compose

  • 找到你的docker-compose目录,通常容器名称以项目名称开头,然后进入它的目录。
  • executedocker-compose down

码头工人

  • 尝试重新启动docker守护进程。例如,在基于Linux的环境中:sudo systemctl restart docker
  • 重启你的机器应该也能工作。

最后,您应该能够按照您的问题所建议的删除容器。

最新更新