Open lvycoder opened 1 year ago
docker 的镜像是分层设计,镜像层是只读的,通过镜像启动的容器添加了一层可读写的文件系统,用户写入的数据都保存在这一层 如果要将写入到容器的数据永久保存,则需要将容器的数据保存在宿主机的指定目录.
[pre] root@m1:/home/lixie# docker inspect 99a1202bd98a | jq '.[].GraphDriver' { "Data": { "LowerDir": "/var/lib/docker/overlay2/e6b65593cb86b4a72aa6e5ae540e6dbabcede9227d166f184d50bebcf7c2ff20-init/diff:/var/lib/docker/overlay2/9a9dfb4184248a5a40fd1b6fa8aaf8e89dd44168c2e7222c2f152aec72a553bc/diff", "MergedDir": "/var/lib/docker/overlay2/e6b65593cb86b4a72aa6e5ae540e6dbabcede9227d166f184d50bebcf7c2ff20/merged", "UpperDir": "/var/lib/docker/overlay2/e6b65593cb86b4a72aa6e5ae540e6dbabcede9227d166f184d50bebcf7c2ff20/diff", "WorkDir": "/var/lib/docker/overlay2/e6b65593cb86b4a72aa6e5ae540e6dbabcede9227d166f184d50bebcf7c2ff20/work" }, "Name": "overlay2" }
[pre] root@m1:/home/lixie# docker ps -a |grep ubuntu 99a1202bd98a ubuntu:22.04 "/bin/bash" 12 minutes ago Exited (137) 5 seconds ago ubuntu [pre] root@m1:/home/lixie# [pre] root@m1:/home/lixie# docker inspect 99a1202bd98a | jq '.[].GraphDriver' { "Data": { "LowerDir": "/var/lib/docker/overlay2/e6b65593cb86b4a72aa6e5ae540e6dbabcede9227d166f184d50bebcf7c2ff20-init/diff:/var/lib/docker/overlay2/9a9dfb4184248a5a40fd1b6fa8aaf8e89dd44168c2e7222c2f152aec72a553bc/diff", "MergedDir": "/var/lib/docker/overlay2/e6b65593cb86b4a72aa6e5ae540e6dbabcede9227d166f184d50bebcf7c2ff20/merged", "UpperDir": "/var/lib/docker/overlay2/e6b65593cb86b4a72aa6e5ae540e6dbabcede9227d166f184d50bebcf7c2ff20/diff", "WorkDir": "/var/lib/docker/overlay2/e6b65593cb86b4a72aa6e5ae540e6dbabcede9227d166f184d50bebcf7c2ff20/work" }, "Name": "overlay2" }
如果删除 ubuntu 容器查看(发现容器信息全部被删除)
[pre] root@m1:/home/lixie# docker rm 99a1202bd98a 99a1202bd98a [pre] root@m1:/home/lixie# docker inspect 99a1202bd98a | jq '.[].GraphDriver' Error: No such object: 99a1202bd98a
前言
docker 的镜像是分层设计,镜像层是只读的,通过镜像启动的容器添加了一层可读写的文件系统,用户写入的数据都保存在这一层 如果要将写入到容器的数据永久保存,则需要将容器的数据保存在宿主机的指定目录.
如果删除 ubuntu 容器查看(发现容器信息全部被删除)