Skip to content

Instantly share code, notes, and snippets.

@b-mc
Created February 25, 2021 18:03
Show Gist options
  • Select an option

  • Save b-mc/58cbbabf45bfd11f2f094cd141993aac to your computer and use it in GitHub Desktop.

Select an option

Save b-mc/58cbbabf45bfd11f2f094cd141993aac to your computer and use it in GitHub Desktop.
Docker: List bind mounts

Docker: List bind mounts

Command

Lately I have found myself working a lot with containers with bind mounts and found no elegant way to display all of them in one go. The command below gives you a nice overview as a json array. You need to have jq installed.

docker inspect $(docker ps -a -q) | jq '[.[] | {Id: .Id[0:12], Name: .Config.Hostname, Image: .Config.Image, Binds: .HostConfig.Binds}]'

Example output

[
  {
    "Id": "0b45da2797b0",
    "Name": "container-1",
    "Image": "image.store/example-image:latest",
    "Binds": [
      "/srv/docker/dir1/:/etc/config/svc:ro",
      "/srv/docker/common/:/etc/config/common/:ro"
    ]
  },
  {
    "Id": "e7d52c7ee759",
    "Name": "container-2",
    "Image": "image.store/example-image:latest",
    "Binds": [
      "/srv/docker/dir2/:/etc/config/svc:ro",
      "/var/app/:/var/app:rw",
      "/srv/docker/common/:/etc/config/common/:ro"
    ]
  },
  {
    "Id": "71bdfcbd47a6",
    "Name": "container-3",
    "Image": "image.store/example-image:latest",
    "Binds": [
      "/srv/docker/dir3/:/etc/config/svc:ro",
      "/srv/docker/common/:/etc/config/common/:ro"
    ]
  }
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment