使用 docker inspect 和 jq 命令快速查看容器挂载目录、docker-compose.yaml 路径 作者: Chuwen 时间: 2024-07-31 分类: 神奇技巧 关于 `jq` 命令的详细解释及安装教程:https://wangchujiang.com/linux-command/c/jq.html --- 语法: ```shell docker inspect | jq '.[0].Mounts' ``` 例如: ```shell shine@Shine-Win11:~/documents/self-projects/tmp$ docker inspect aa3f359ddc0e | jq '.[0].Mounts' [ { "Type": "bind", "Source": "/home/shine/documents/git/projects/docker-elk/elasticsearch/config/elasticsearch.yml", "Destination": "/usr/share/elasticsearch/config/elasticsearch.yml", "Mode": "ro,Z", "RW": false, "Propagation": "rprivate" }, { "Type": "volume", "Name": "docker-elk_elasticsearch", "Source": "/var/lib/docker/volumes/docker-elk_elasticsearch/_data", "Destination": "/usr/share/elasticsearch/data", "Driver": "local", "Mode": "z", "RW": true, "Propagation": "" } ] ``` ![](https://cdn.nowtime.cc/2024/07/31/3809813538.png) ## 查看 docker-compose.yaml 路径 语法: ```shell docker inspect | jq '.[0].Config.Labels' ``` 示例: ```shell shine@Shine-Win11:~/documents/git/projects/docker-elk$ docker inspect 8334b593b89a | jq '.[0].Config.Labels' { "com.docker.compose.config-hash": "d1f80fc712ff55f9f33eafc4842bf71f947a6584b27eb548bca0c0dc399bff8b", "com.docker.compose.container-number": "1", "com.docker.compose.depends_on": "", "com.docker.compose.image": "sha256:de7d209b219972d54381f0a7d18671d0c3aa1f3b4410a607cb82d34a08a97dc8", "com.docker.compose.oneoff": "False", "com.docker.compose.project": "frankenphp-typecho", "com.docker.compose.project.config_files": "/mnt/c/Users/Shine/Documents/Self/projects/frankenphp-typecho/docker-compose.yaml", "com.docker.compose.project.working_dir": "/mnt/c/Users/Shine/Documents/Self/projects/frankenphp-typecho", "com.docker.compose.replace": "3a7bd46c1737dd0ce32be2e6f4b246ca3e2778bbc83d105579c994e8fadc3a17", "com.docker.compose.service": "wordpress", "com.docker.compose.version": "2.24.7", "org.opencontainers.image.created": "2024-04-23T12:51:06Z", "org.opencontainers.image.description": "The modern PHP app server", "org.opencontainers.image.licenses": "MIT", "org.opencontainers.image.revision": "a9ebc3aeea590b45422a19510473955b372d09aa", "org.opencontainers.image.source": "https://github.com/dunglas/frankenphp", "org.opencontainers.image.title": "FrankenPHP", "org.opencontainers.image.url": "https://frankenphp.dev", "org.opencontainers.image.vendor": "Kévin Dunglas", "org.opencontainers.image.version": "v1.1.3" } ``` ![](https://cdn.nowtime.cc/2024/07/31/1733369616.png) 标签: Docker