docker存储文件在哪里?

docker存储文件在哪里?

我创建了一个 docker 实例并将一些文件保存到 home。当我重新连接到实例时,文件就在那里:

$ sudo docker start 09d9a9dfe53d
09d9a9dfe53d

$ sudo docker attach 09d9a9dfe53d
root@09d9a9dfe53d:/# cat /home/aaa/myfile
Hello world

这些文件存放在哪里?

在主机上我有

/var/lib/docker/volumes# ls -l
total 24
brw------- 1 root root  8, 1 янв 16 14:43 backingFsBlockDev
-rw------- 1 root root 32768 янв 16 14:43 metadata.db

myfile这儿?


如果容器停止,文件不会消失,证明:

$ sudo docker run -it ubuntu bash
root@c7033ac0fdd2:/# cd home
root@c7033ac0fdd2:/home# ls
root@c7033ac0fdd2:/home# mkdir mydir
root@c7033ac0fdd2:/home# cd mydir
root@c7033ac0fdd2:/home/mydir# echo "Hello world" > myfile.txt
root@c7033ac0fdd2:/home/mydir# ls
myfile.txt
root@c7033ac0fdd2:/home/mydir# cat myfile.txt
Hello world
root@c7033ac0fdd2:/home/mydir# exit
exit
$ sudo docker ps
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES
$ sudo docker ps -a
CONTAINER ID   IMAGE         COMMAND                  CREATED              STATUS                      PORTS     NAMES
c7033ac0fdd2   ubuntu        "bash"                   About a minute ago   Exited (0) 19 seconds ago             reverent_shirley
...
$ sudo docker start c7033ac0fdd2
c7033ac0fdd2
$ sudo docker ps
CONTAINER ID   IMAGE     COMMAND   CREATED              STATUS         PORTS     NAMES
c7033ac0fdd2   ubuntu    "bash"    About a minute ago   Up 9 seconds             reverent_shirley
$ sudo docker attach c7033ac0fdd2
root@c7033ac0fdd2:/# cat /home/mydir/myfile.txt
Hello world
root@c7033ac0fdd2:/# exit
exit

findmnt结果:

root@c7033ac0fdd2:/# findmnt /
TARGET SOURCE  FSTYPE  OPTIONS
/      overlay overlay rw,relatime,lowerdir=/var/lib/docker/overlay2/l/4UV6PPC43YODQZYSDFVT35PNPR:/var/lib/docker/overlay2/l/2JI5EVHDBQUZNAN3AT5ZI3OFHI:/var/lib/docker/overlay2/l/IFJUJWCIKH4VPFKVU7XZZ3KBHD:/var/lib/docker/overlay2/l/NJ5DQNTMPOFFWOATHFLO6AYPWQ,upperdir=/var/lib/docker/overlay2/5f45f5c68e1d77683ee6be1395d

相关内容