How to determine what containers use the docker volume? How to determine what containers use the docker volume? docker docker

How to determine what containers use the docker volume?


docker ps can filter by volume to show all of the containers that mount a given volume:

docker ps -a --filter volume=VOLUME_NAME_OR_MOUNT_POINT

Reference: https://docs.docker.com/engine/reference/commandline/ps/#filtering


This is related to jwodder suggestion, if of any help to someone.It basically gives the summary of all the volumes, in case you have more than a couple and are not sure, which is which.

import ioimport subprocessimport pandas as pdresults = subprocess.run('docker volume ls', capture_output=True, text=True)df = pd.read_csv(io.StringIO(results.stdout),                 encoding='utf8',                 sep="    ",                 engine='python')for i, row in df.iterrows():    print(i, row['VOLUME NAME'])    print('-' * 20)    cmd = ['docker', 'ps', '-a', '--filter', f'volume={row["VOLUME NAME"]}']    print(subprocess.run(cmd,           capture_output=True, text=True).stdout)    print()