Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docker volumes are not being cleaned up automatically on the host when the associated container gets deleted from the host #5069

Closed
bkumar08 opened this issue May 13, 2024 · 2 comments

Comments

@bkumar08
Copy link

Description

Docker volumes are created only for images that have the VOLUME instruction, such as 'vault'. For example, if you pull any image that has a volume and run a container from it, the volume will be created automatically. However, when you delete the container from the host, the volume should also be deleted. But docker service is not deleting them automatically, resulting in an increase in file count and ultimately consuming disk space.

To fix this issue, we have to manually clean up from the host (docker volume rm $(docker volume ls -q)), which is not the expected behavior. Docker should manage this internally; whenever an associated container gets deleted, all volumes should also be deleted from the host belongs to deleted containers.

Reproduce

  • Try to create a container on any image which has VOLUME attached to it (e.g, vault:1.13.3)
  • Docker run command to create a container (docker run -itd vault:1.13.3)
  • Now check the docker volume (docker volume ls or docker system df -v), you will see the volume created with size 0B since no file attached to it . but for my case i have own application docker image which has multiple files which large size
    VOLUME NAME LINKS SIZE 6c2fc8c9a20ebbf4d344aca9b0c72c388188ee36d65eb8fe7afa949fefd49152 0 0B 8e9ceb5c2149cc5077f1d305572d685cdc11de32c74d16e9522aae5a1a08497c 0 2.22GB 2bef84507c17587ecdca16fe24fe7af25f98943c61031a76d44ffecc15c9859e 0 3.215GB

Expected behavior

whenever an associated container gets deleted, all volumes should also be deleted from the host belongs to deleted containers

docker version

[root@ip-10-82-11-35 ec2-user]# docker version
Client:
 Version:           20.10.25
 API version:       1.41
 Go version:        go1.20.12
 Git commit:        b82b9f3
 Built:             Fri Dec 29 20:37:18 2023
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true

Server:
 Engine:
  Version:          20.10.25
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.20.12
  Git commit:       5df983c
  Built:            Fri Dec 29 20:38:05 2023
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.7.11
  GitCommit:        64b8a811b07ba6288238eefc14d898ee0b5b99ba
 runc:
  Version:          1.1.11
  GitCommit:        4bccb38cc9cf198d52bebf2b3a90cd14e7af8c06
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0
[root@ip-10-82-11-35 ec2-user]# 
OS: 
[root@ip-10-82-11-35 ec2-user]# cat /etc/os-release 
NAME="Amazon Linux"
VERSION="2"
ID="amzn"
ID_LIKE="centos rhel fedora"
VERSION_ID="2"
PRETTY_NAME="Amazon Linux 2"
ANSI_COLOR="0;33"
CPE_NAME="cpe:2.3:o:amazon:amazon_linux:2"
HOME_URL="https://amazonlinux.com/"
SUPPORT_END="2025-06-30"
[root@ip-10-82-11-35 ec2-user]# 
NOTE: I am able to reproduce on other OS and latest version of docker [ubuntu:22.04 and docker version: 1.25]

docker info

[root@ip-10-82-11-35 ec2-user]# docker info
Client:
 Context:    default
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc., v0.0.0+unknown)

Server:
 Containers: 1
  Running: 1
  Paused: 0
  Stopped: 0
 Images: 4
 Server Version: 20.10.25
 Storage Driver: overlay2
  Backing Filesystem: xfs
  Supports d_type: true
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Cgroup Version: 1
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: io.containerd.runc.v2 io.containerd.runtime.v1.linux runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 64b8a811b07ba6288238eefc14d898ee0b5b99ba
 runc version: 4bccb38cc9cf198d52bebf2b3a90cd14e7af8c06
 init version: de40ad0
 Security Options:
  seccomp
   Profile: default
 Kernel Version: 4.14.326-245.539.amzn2.x86_64
 Operating System: Amazon Linux 2
 OSType: linux
 Architecture: x86_64
 CPUs: 2
 Total Memory: 3.838GiB
 Name: ip-10-82-11-35
 ID: 36AY:33SS:PXWV:6K2T:LFWM:2B77:OAH3:SXQA:HTL3:XCHJ:QG5G:W5VA
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Registry: https://index.docker.io/v1/
 Labels:
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false

Additional Info

No response

@bkumar08
Copy link
Author

I am observing the same issue in latest docker version 25.0.3
[root@ip-10-82-8-97 ec2-user]# docker version
Client:
Version: 25.0.3
API version: 1.44
Go version: go1.20.12
Git commit: 4debf41
Built: Mon Feb 12 00:00:00 2024
OS/Arch: linux/amd64
Context: default

Server:
Engine:
Version: 25.0.3
API version: 1.44 (minimum version 1.24)
Go version: go1.20.12
Git commit: f417435
Built: Mon Feb 12 00:00:00 2024
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.7.11
GitCommit: 64b8a811b07ba6288238eefc14d898ee0b5b99ba
runc:
Version: 1.1.11
GitCommit: 4bccb38cc9cf198d52bebf2b3a90cd14e7af8c06
docker-init:
Version: 0.19.0
GitCommit: de40ad0

@thaJeztah
Copy link
Member

This is the expected behavior; docker does not delete volumes by default (even if they are anonymous volumes); the only exception here is when running a container with the --rm option set, which deletes both the container and anonymous volumes associated with it when the container exits; https://docs.docker.com/reference/cli/docker/container/run/#rm

To do the same when manually deleting a container, use the -v / --volumes options on docker rm / docker container rm; https://docs.docker.com/reference/cli/docker/container/rm/#volumes

Note that this will not delete "named" volumes (volumes that were explicitly created with a name).

Also note that Docker 20.10 reached EOL, and is no longer maintained; if possible, I'd recommend upgrading to a currently supported version.

I'll close this ticket, because this looks to be working as expected, but feel free to continue the conversation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants