Programming

Docker가 사용중인 볼륨에 있지만 Docker 컨테이너가 없습니다.

procodes 2020. 8. 15. 14:27
반응형

Docker가 사용중인 볼륨에 있지만 Docker 컨테이너가 없습니다.


Docker 1.9.1에서 Docker 볼륨을 제거하는 데 문제가 있습니다.

중지 된 모든 컨테이너를 제거하여 docker ps -a빈 반환합니다.

를 사용 docker volume ls하면 전체 Docker 컨테이너가 제공됩니다.

docker volume ls
DRIVER              VOLUME NAME
local               a94211ea91d66142886d72ec476ece477bb5d2e7e52a5d73b2f2f98f6efa6e66
local               4f673316d690ca2d41abbdc9bf980c7a3f8d67242d76562bbd44079f5f438317
local               eb6ab93effc4b90a2162e6fab6eeeb65bd0e4bd8a9290e1bad503d2a47aa8a78
local               91acb0f7644aec16d23a70f63f70027899017a884dab1f33ac8c4cf0dabe5f2c
local               4932e2fbad8f7e6246af96208d45a266eae11329f1adf176955f80ca2e874f69
local               68fd38fc78a8f02364a94934e9dd3b5d10e51de5b2546e7497eb21d6a1e7b750
local               7043a9642614dd6e9ca013cdf662451d2b3df6b1dddff97211a65ccf9f4c6d47
#etc x 50

이러한 볼륨에는 중요한 내용이 포함되어 있지 않기 때문에를 사용하여 모든 볼륨을 제거하려고합니다 docker volume rm $(docker volume ls -q).

이 과정에서 대다수가 제거되지만 다시 돌아옵니다.

Error response from daemon: Conflict: volume is in use
Error response from daemon: Conflict: volume is in use
Error response from daemon: Conflict: volume is in use
Error response from daemon: Conflict: volume is in use
Error response from daemon: Conflict: volume is in use

그들 중 상당 부분. 처음에 컨테이너가없는 경우 이러한 볼륨은 어떻게 사용됩니까?


이러한 함수를 사용하여 Docker와 관련된 모든 것을 잔인하게 제거 할 수 있습니다.

removecontainers() {
    docker stop $(docker ps -aq)
    docker rm $(docker ps -aq)
}

armageddon() {
    removecontainers
    docker network prune -f
    docker rmi -f $(docker images --filter dangling=true -qa)
    docker volume rm $(docker volume ls --filter dangling=true -q)
    docker rmi -f $(docker images -qa)
}

이를 ~/Xrc파일에 추가 할 수 있습니다 . 여기서 X는 쉘 인터프리터 ( ~/.bashrcbash를 사용하는 경우) 파일이며 source ~/Xrc. 또한 콘솔에 복사하여 붙여넣고 나중에 (기능을 준비하기 위해 이전에 선택한 옵션에 관계없이) 다음을 실행하면됩니다.

armageddon

일반적인 Docker 정리에만 유용합니다. 이렇게하면 컨테이너 (실행 중이 든 아니든) 및 모든 종류의 볼륨뿐만 아니라 이미지도 제거된다는 점을 명심하십시오.


볼륨이 docker-compose? 를 통해 생성되었을 수 있습니다 . 그렇다면 다음을 통해 제거 해야합니다 .

docker-compose down --volumes

Niels Bech Nielsen에 대한 크레딧 !


저는 Docker를 처음 사용합니다. 나는 초기 테스트 엉망을 정리하고 있었고 볼륨도 제거 할 수 없었다. 실행중인 모든 인스턴스를 중지하고을 수행 docker rmi -f $(docker image ls -q)했지만 여전히 Error response from daemon: unable to remove volume: remove uuid: volume is in use.

나는 a를 docker system prune했고 마지막 볼륨을 제거하는 데 필요한 것을 정리했습니다.

[0]$ docker system prune
WARNING! This will remove:
- all stopped containers
- all networks not used by at least one container
- all dangling images
- all build cache
Are you sure you want to continue? [y/N] y
Deleted Containers:
... about 15 containers UUID's truncated

Total reclaimed space: 2.273MB
[0]$ docker volume ls
DRIVER              VOLUME NAME
local              uuid
[0]$ docker volume rm uuid
uuid
[0]$

docker system prune

이 명령을 사용하려면 클라이언트 및 데몬 API가 둘 다 1.25 이상이어야합니다. docker version클라이언트 에서 명령을 사용 하여 클라이언트 및 데몬 API 버전을 확인합니다.


중지 된 컨테이너 중 하나에서 볼륨을 사용할 수 있습니다. 다음 명령으로 이러한 컨테이너를 제거 할 수 있습니다.

docker container prune

그런 다음 사용하지 않는 볼륨을 제거 할 수 있습니다.

docker volume prune

볼륨이 컨테이너와 연결되어있는 한 (실행 중이 든 아니든) 제거 할 수 없습니다.

당신은 실행해야

docker inspect <container-id>/<container-name>

이 볼륨이 마운트되었을 수있는 각 실행 / 비 실행 컨테이너에서.

If the volume is mounted onto any one of the containers, you should see it in the Mounts section of the inspect command output. Something like this :-

"Mounts": [
            {
                "Type": "volume",
                "Name": "user1",
                "Source": "/var/lib/docker/volumes/user1/_data",
                "Destination": "/opt",
                "Driver": "local",
                "Mode": "",
                "RW": true,
                "Propagation": ""
            }
        ],

After figuring out the responsible container(s), use :-

docker rm -f container-1 container-2 ...container-n in case of running containers

docker rm container-1 container-2 ...container-n in case of non-running containers

to completely remove the containers from the host machine.

Then try removing the volume using the command :-

docker volume remove <volume-name/volume-id>


I am pretty sure that those volumes are actually mounted on your system. Look in /proc/mounts and you will see them there. You will likely need to sudo umount <path> or sudo umount -f -n <path>. You should be able to get the mounted path either in /proc/mounts or through docker volume inspect


Currently you can use what docker offers now for a general and more complete cleaning:

docker system prune

To additionally remove any stopped containers and all unused images (not just dangling images), add the -a flag to the command:

docker system prune -a

You should type this command with flag -f (force):

sudo docker volume rm -f <VOLUME NAME>

참고URL : https://stackoverflow.com/questions/34658836/docker-is-in-volume-in-use-but-there-arent-any-docker-containers

반응형