如何确定 Docker 下载的镜像对应的目录

2018-12-18 14:17:21 +08:00
 DearTanker

在黑群晖里面折腾 Docker 遇到一个比较棘手的问题,Google 了几个月没找到方法。

下载了几个 image 镜像:

root@HP-Gen8-DSM:~# docker images
3REPOSITORY                    TAG                 IMAGE ID            CREATED             SIZE
atlassian/confluence-server   6.13.0              7b1705b3ff8f        2 weeks ago         981MB
dpage/pgadmin4                3.6                 885166b71c10        3 weeks ago         262MB
postgres                      9.6.9               106bdfb062df        4 months ago        235MB

但是不知道对应镜像目录是哪个:

root@HP-Gen8-DSM:/volume1/@docker/btrfs/subvolumes# ll
total 0
drwx------ 1 root root 6430 Dec 17 20:17 .
drwx------ 1 root root   20 Dec 17 14:27 ..
drwxr-xr-x 1 root root  184 Dec 17 18:18 0177d981c89a9749c2723da2b23c798b49a8aa957f57ede4ab0d262c086d0cd6
drwxr-xr-x 1 root root  170 Dec 17 19:24 0819c021ac86443a7c23530ca8a3c9506a62dad6a81c5d2907649adc8bd0f6f3
drwxr-xr-x 1 root root  170 Dec 17 19:24 0819c021ac86443a7c23530ca8a3c9506a62dad6a81c5d2907649adc8bd0f6f3-init
drwxr-xr-x 1 root root  124 Dec 17 18:19 08329ceddaa61aabcf84cfbe892b5f13fab4cfcfbc9c8b77355ba05c050d8ddd
drwxr-xr-x 1 root root  108 Dec 17 18:19 0a10c5bb87be69ffb744fc3dbd4a876bb886d14100119bc3fa0422b96a9a0974
drwxr-xr-x 1 root root  132 Dec 17 18:18 0aa85aa90f65339fa122a63aae7c28d9dbe62829474b4188110500c855ff1d3f
drwxr-xr-x 1 root root  184 Dec 17 18:18 1cc56e0e088fc8a0a40f4006bc622e1c2edcde6fe09a33bfd9d896a766ac1da9
drwxr-xr-x 1 root root  108 Dec 17 18:19 2328a6636b1a0b955999fea881f29ed5546b0c22d82198da8f6f32702fcbd1e5
drwxr-xr-x 1 root root  108 Dec 17 18:19 2557e744b7f04ca112373459f9f2d1b0d0a60bce009948ee52533ab96f1e6b4e
drwxr-xr-x 1 root root  124 Dec 17 18:19 3191de7e4bae4ca1c7ba399b7c7ce1841afce9df0eaadb1bd11246a150a3bc0b
drwxr-xr-x 1 root root  132 Dec 17 18:15 3275e20a52b655413cde6868cce47c5b2efd82ae6115e38a42c03de7e9c26b8d
drwxr-xr-x 1 root root  132 Dec 17 18:15 33ed864d32cc848ceee12bcb072b27de12d2f6d3e830c6e447cb12f02376dfae
drwxr-xr-x 1 root root  124 Dec 17 18:19 396b7b1f3c551e8870b8bd0627c44187106c9755fc7a8637aa23d6b9694ff55b
drwxr-xr-x 1 root root  132 Dec 17 18:15 536f5f50d92f6729d0f9909b69e6080844ac57f7b29b35386e18ef631442534a
drwxr-xr-x 1 root root  108 Dec 17 18:19 53c71f045525ca35f849f5f1f43bee9dffc0d048fc8612b13571dd762b84b1c4
drwxr-xr-x 1 root root  184 Dec 17 18:18 5f279b09c8a3a836cf920d1b542001173841b9dd731b6285f61d823b7fc22c95
drwxr-xr-x 1 root root  108 Dec 17 18:19 632e988754fec38d40a864fbf961988e6cd2a70bded7d8db9a270d4dddaf827e
drwxr-xr-x 1 root root  132 Dec 17 18:15 6c9715a622c2984785a8af71b8c7d9a2dc14094d4b7027423a1247e9d0820256
drwxr-xr-x 1 root root  108 Dec 17 18:19 6f599819bc0890c39a8a93e890b5c1a82504feabd2bfa17ee3affd8ea98a21ab
drwxr-xr-x 1 root root  184 Dec 17 18:18 767d6c74de2be179f730ff040c7974a83554469cf43bb1ca38cd0b59ee0e456d
drwxr-xr-x 1 root root  158 Dec 17 18:16 7bf9e07cf56314b6040fed57320f6b258f0a4b4e77b4be3d23ace0f7ef3988d4
drwxr-xr-x 1 root root  124 Dec 17 18:19 80e5e45b4318224cf527e1b9937e4485c58ac0ff2bd9dbf84e97cb561809b12a
drwxr-xr-x 1 root root  132 Dec 17 18:18 82511c81640e1129dca589432173d1b9a13d2f31aad6419622aaba0db6f7273c
drwxr-xr-x 1 root root  158 Dec 17 18:15 8573f1b901ac4984a430398275876b667c271e82572c8f6f41f3a31ce012cedf
drwxr-xr-x 1 root root  132 Dec 17 18:18 8da80ee80af713be3007515384073776acad7dd3580627ee61aed96989dacfd4
drwxr-xr-x 1 root root  132 Dec 17 18:18 a7c9bb64e258f62ced431a2c648df40c475f4cd839189a19f21fb61b0d21b3e6
drwxr-xr-x 1 root root  132 Dec 17 18:15 aaa7ef3c77e09c89776ccbf61019660fbbdd01183489b24b89b95503e06dc1f5
drwxr-xr-x 1 root root  108 Dec 17 18:19 ad5a0ee34c849bde85ea518ea9c487e6a2d1fcd3694c77ea5afdadb593650616
drwxr-xr-x 1 root root  124 Dec 17 18:19 afa47768b6f54d4fac2214a86f928609f8cf8fac1ee904a17c80daa54047d98f
drwxr-xr-x 1 root root  132 Dec 17 18:15 b00f1c4c4d5143b7a57043d3a1e3ae76b374bedb564e3c2bf761360f83abe961
drwxr-xr-x 1 root root  184 Dec 17 18:18 b0d329b4f38a524f4816a51ccd4214f484c829984acd6df96a52aced60c825b1
drwxr-xr-x 1 root root  124 Dec 17 18:19 b3a5eed179c10ca31e7b9cd450fd2bdcc19b250f10eaadf6b8f3d4e86e72e64a
drwxr-xr-x 1 root root  184 Dec 17 18:18 be0c6e6bc457624601898ba4a9ca7526c3a09727471370c6d7d1767b84c6fa14
drwxr-xr-x 1 root root  184 Dec 17 18:18 c3a8a4ed911ac251f316c62c43aea2439601dfc405cbf8ce5e9384a0d2980506
drwxr-xr-x 1 root root  224 Dec 17 18:18 ceb87bb0139f94cdfde3b368875fab2e8321f6d61fca468f7c50022ed6d32e57
drwxr-xr-x 1 root root  124 Dec 17 18:19 d074f013df36ebcebf09244d52ee6efde76880aea7f8ad3d6a8f7de4a515a94f
drwxr-xr-x 1 root root  244 Dec 17 19:23 d6faeada9ab6282809df310f152c3e9589a1ddb0166cbde07c5446c27e5945f4
drwxr-xr-x 1 root root  244 Dec 17 19:23 d6faeada9ab6282809df310f152c3e9589a1ddb0166cbde07c5446c27e5945f4-init
drwxr-xr-x 1 root root  124 Dec 17 18:19 d8b3b09628c9055d36277662fd1ea98170310d180304f4a02f2ae0b486623b0e
drwxr-xr-x 1 root root  124 Dec 17 18:19 d9dcb1b9c48fc9a70f371ba508dc76d4d0e664fd3cf53ebc26d981db8e044697
drwxr-xr-x 1 root root  132 Dec 17 18:15 da97952a5e2a77adf0fb34540a6509b5fbe7f98b02e060b40342fb7dd6ecb15e
drwxr-xr-x 1 root root  132 Dec 17 18:18 e6be116618a839f751c9a91275b37f68ee94175ec71ed76d9892332fd898fc3d
drwxr-xr-x 1 root root  132 Dec 17 18:15 e84657e39df5b998ba5389813c583d7ea617e34cb06364b15fcd306421c44292
drwxr-xr-x 1 root root  158 Dec 17 18:15 ea658bb2aa6f75cf7c484ad8e384a1da9cb04f4c2e6c9dbbef672bd52417c62e
drwxr-xr-x 1 root root  132 Dec 17 18:15 f3797551e573ed255bf373f9cf9d283adf431d807f5c87303a2789fe487540cf
drwxr-xr-x 1 root root  178 Dec 17 19:21 f592ff402f4dbf6ac0f70bbb6167d089ffdc908a67f471acbfb99a592be4bbae
drwxr-xr-x 1 root root  178 Dec 17 19:21 f592ff402f4dbf6ac0f70bbb6167d089ffdc908a67f471acbfb99a592be4bbae-init
drwxr-xr-x 1 root root  124 Dec 17 18:19 f832bc4d54209fe5e3ff50cdbe6644ef98a8587fbbc971ef8d310c6bd111fcb2
drwxr-xr-x 1 root root  132 Dec 17 18:18 fcc271a7ea6ba4dd3ea35a2134738b8938f23f9d7cf39d97ed3e9a64a3f1d57d
drwxr-xr-x 1 root root  150 Dec 17 18:19 fd5c40d5c4cc7a0bd1e14cd7505e59b2014fcc63e20074e85f725ed5342104a3

现在的办法是手动一个个去点击打开目录或者通过 df 查看目录占用大小来判断是不是想要的镜像。这也太蠢了吧。

另外,我只知道如果运行了某个镜像的容器,会生成一个同名 - init 的新映像目录。

希望有熟悉 Docker 的朋友可以告诉我确认镜像目录更好的办法。

10359 次点击
所在节点    Docker
23 条回复
shakespaces
2018-12-18 14:22:12 +08:00
借楼问一下,我群晖 docker 总遇到映射文件夹在容器中没有权限的问题,有没有人遇到同样的情况及解决方法😛
Herobs
2018-12-18 14:22:39 +08:00
inspect 有详细信息
DearTanker
2018-12-18 14:29:31 +08:00
@Herobs #2 通过这个查询到

```
root@HP-Gen8-DSM:/volume1/@docker/btrfs/subvolumes# docker inspect 7b1705b3ff8f
[
{
"Id": "sha256:7b1705b3ff8f3a810336dc31e63793a73aea5874ef7daf38ee168a85cc246642",
"RepoTags": [
"atlassian/confluence-server:6.13.0"
],
"RepoDigests": [
"atlassian/confluence-server@sha256:2d8381cb668b4f49c4f88ae8039d79b9864c48653e4277667a6030cb0bb7a518"
],
"Parent": "",
"Comment": "",
"Created": "2018-12-04T03:18:14.922379922Z",
"Container": "71dc6d675ea4e69dd3e8e24351d3677f3f1f39f947ba4ddb500fc24cf75cbd54",
"ContainerConfig": {
"Hostname": "",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": false,
"AttachStderr": false,
"ExposedPorts": {
"8090/tcp": {},
"8091/tcp": {}
},
"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": [
"PATH=/opt/java/openjdk/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"JAVA_VERSION=jdk8u192-b12",
"JAVA_HOME=/opt/java/openjdk",
"JAVA_TOOL_OPTIONS=-XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap",
"RUN_USER=daemon",
"RUN_GROUP=daemon",
"CONFLUENCE_HOME=/var/atlassian/application-data/confluence",
"CONFLUENCE_INSTALL_DIR=/opt/atlassian/confluence"
],
"Cmd": [
"|2",
"CONFLUENCE_VERSION=6.13.0",
"DOWNLOAD_URL=http://www.atlassian.com/software/confluence/downloads/binary/atlassian-confluence-6.13.0.tar.gz",
"/bin/sh",
"-c",
"mkdir -p ${CONFLUENCE_INSTALL_DIR} && curl -L --silent ${DOWNLOAD_URL} | tar -xz --strip-components=1 -C \"$CONFLUENCE_INSTALL_DIR\" && chown -R ${RUN_USER}:${RUN_GROUP} ${CONFLUENCE_INSTALL_DIR}/ && sed -i -e 's/-Xms\\([0-9]\\+[kmg]\\) -Xmx\\([0-9]\\+[kmg]\\)/-Xms\\${JVM_MINIMUM_MEMORY:=\\1} -Xmx\\${JVM_MAXIMUM_MEMORY:=\\2} \\${JVM_SUPPORT_RECOMMENDED_ARGS} -Dconfluence.home=\\${CONFLUENCE_HOME}/g' ${CONFLUENCE_INSTALL_DIR}/bin/setenv.sh && sed -i -e 's/port=\"8090\"/port=\"8090\" secure=\"${catalinaConnectorSecure}\" scheme=\"${catalinaConnectorScheme}\" proxyName=\"${catalinaConnectorProxyName}\" proxyPort=\"${catalinaConnectorProxyPort}\"/' ${CONFLUENCE_INSTALL_DIR}/conf/server.xml && sed -i -e 's/Context path=\"\"/Context path=\"${catalinaContextPath}\"/' ${CONFLUENCE_INSTALL_DIR}/conf/server.xml"
],
"ArgsEscaped": true,
"Image": "sha256:2618ff728742a424e1f68775038e202da647c73ee711afe088204ae336374e36",
"Volumes": {
"/var/atlassian/application-data/confluence": {}
},
"WorkingDir": "/var/atlassian/application-data/confluence",
"Entrypoint": null,
"OnBuild": null,
"Labels": null,
"DDSM": false
},
"DockerVersion": "18.03.1-ee-3",
"Author": "Atlassian Confluence",
"Config": {
"Hostname": "",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": false,
"AttachStderr": false,
"ExposedPorts": {
"8090/tcp": {},
"8091/tcp": {}
},
"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": [
"PATH=/opt/java/openjdk/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"JAVA_VERSION=jdk8u192-b12",
"JAVA_HOME=/opt/java/openjdk",
"JAVA_TOOL_OPTIONS=-XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap",
"RUN_USER=daemon",
"RUN_GROUP=daemon",
"CONFLUENCE_HOME=/var/atlassian/application-data/confluence",
"CONFLUENCE_INSTALL_DIR=/opt/atlassian/confluence"
],
"Cmd": [
"/entrypoint.sh",
"-fg"
],
"ArgsEscaped": true,
"Image": "sha256:2618ff728742a424e1f68775038e202da647c73ee711afe088204ae336374e36",
"Volumes": {
"/var/atlassian/application-data/confluence": {}
},
"WorkingDir": "/var/atlassian/application-data/confluence",
"Entrypoint": [
"/sbin/tini",
"--"
],
"OnBuild": null,
"Labels": null,
"DDSM": false
},
"Architecture": "amd64",
"Os": "linux",
"Size": 981016296,
"VirtualSize": 981016296,
"GraphDriver": {
"Data": null,
"Name": "btrfs"
},
"RootFS": {
"Type": "layers",
"Layers": [
"sha256:bc7f4b25d0ae3524466891c41cefc7c6833c533e00ba80f8063c68da9a8b65fe",
"sha256:a768c3f3878e96565d2bf0dcf90508261862847b2e7b8fc804a0770c07f0d5d5",
"sha256:ca2991e4676cba899ad9bc6ad3a044cd0816915f9e97a6f2e67b6accbc779ba5",
"sha256:b9b7103af585bd8ae9130de947817be7ce76092aa19cf6d2f9d5290440c645eb",
"sha256:4508b8a3648cf718b2357b9054f11a8167d855fb4025db5bed5e52befd93e905",
"sha256:695236666fc1fcb847e1a02d6be963e676c0435e6f009848efe41b559111e601",
"sha256:84ef2929790df85724c82ff18c2b2e4b85e50703c6ee37915662df37620b9a57",
"sha256:74434a3cc76f134bc962e5e8c80fd3a82b6ec62c350ded6b92ec1aaefbfc7b48",
"sha256:35efee10212a591352472e2b60cfaaeb0e16362aab024df732ac8310c3c421d5",
"sha256:fd61b63656abea55b7b3c35f12035f99f07701285eb8476d778de48f4351ce3d",
"sha256:f77b89f2feccffdc376556e7c74beaabc55f816f94bfa196925fbac184be2feb",
"sha256:1f694c4c9c8a00b1ca5a37c1204b744e893154e7d6781b93b2bfb91a3888321b"
]
}
}
]
```

可是似乎还是没办法知道在 /volume1/@docker/btrfs/subvolumes 中对应的是哪个目录呀。
DearTanker
2018-12-18 14:30:23 +08:00
@shakespaces #1 是不是得开启那个“使用高权限执行容器”?
houzhimeng
2018-12-18 14:41:30 +08:00
"Cmd": [
"php-fpm"
],
"ArgsEscaped": true,
"Image": "php:7.2-fpm",
"Volumes": null,
"WorkingDir": "/var/www/html",
"Entrypoint": [
"docker-php-entrypoint"
],
"OnBuild": null,
"Labels": {}
},
DearTanker
2018-12-18 16:52:59 +08:00
@houzhimeng #5 不是这个目录,是为了找镜像本身放在哪个目录,不是镜像里面的工作目录。
CallMeReznov
2018-12-18 16:56:44 +08:00
DearTanker
2018-12-18 17:00:44 +08:00
@CallMeReznov #7 这个我在 3 楼回复了,貌似找不到的。
alex321
2018-12-18 17:02:12 +08:00
话说,你一定要找到镜像本身放在本地的哪个目录做啥子呢。这个是 docker 自己维护的,它管理着由多个 layer 组成的一个镜像。我猜测可能一个 layer 就是一个文件,然后有个类似配置的 layer 做了原本 dockerfile 的转译,启动时使用转译的这个 layer 来把组成的多个 layer 拼合起来构成一个指定的运行的容器环境。

PS,我不是程序员,仅仅是爱好折腾,不求弄明白各种底层原理,但求能干什么或者怎么干。求不黑。
tomczhen
2018-12-18 17:18:58 +08:00
镜像有导出 /导入命令,没必要去找物理路径。

权限是认 id 不是用户名,处理一下就行。

推荐 Portainer。
wzxjohn
2018-12-18 18:05:44 +08:00
镜像本身是分层存储的,没有所谓的一个镜像对应一个目录吧。。。为啥要找这个呢?
DearTanker
2018-12-18 18:18:05 +08:00
@alex321 #9
@tomczhen #10
@wzxjohn #11

因为要进去替换文件、修改文件。。
cccssss
2018-12-18 18:24:14 +08:00
@DearTanker 替换文件修改文件不是一般都用 Dockerfile 搞定,然后自己再 save 一个出来或者 push 重新发布一下?
还是我理解的你替换文件是直接修改像 9 楼说的 layer 二进制文件啥的?
wbrobot
2018-12-18 18:27:21 +08:00
docker exec -it 容器 /bin/bash
进容器里面拷出来
jinyang656
2018-12-18 18:32:01 +08:00
@DearTanker #12 替换修改文件你应该 run 一个容器出来,改完之后 docker commit 产生一个新镜像
DearTanker
2018-12-18 18:53:45 +08:00
@jinyang656 #15 学习了。
wzxjohn
2018-12-18 19:25:49 +08:00
@DearTanker 木有修改镜像本身这种玩法的。如果你想做自己的镜像,就去搞 docker file build 一个出来。如果你只是想要修改镜像 run 出来的容器里面的内容的话,直接用这个镜像起一个新的容器,然后 ssh 进去随便搞就可以啦
0312birdzhang
2018-12-18 19:41:50 +08:00
一个最简单的方法是挂载一个目录用 #14 的方法拷出来,然后运行的时候再把这个目录挂上。(好吧,也不简单,手动狗头
GuryYu
2018-12-18 20:48:26 +08:00
@DearTanker 要复制替换容器内文件直接 docker cp 命令不就可以了吗
leopku
2018-12-18 23:05:42 +08:00
@shakespaces 给目录加上 everyone 所有权限

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/518607

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX